Now I am having a problem:
I am building a chat application, when from the LINE app click on the start chat button, it will transfer the user to the chat website dedicated to them. Currently when processing on Android, everything is still displayed normally, but when I build on iOS, nothing is displayed.
Regarding the technology used, I use spring boot, thymeleaf combined with jQuery + LIFF SDK.
The process when init the screen I am processing: When init the screen for the first time, the backend will check the isInit variable passed is null, then it will return the html of that screen.
My Server:
public String init(
@RequestParam(value = "liffChannelId") String liffChannelId,
@RequestParam(value = "messageChannelId") String messageChannelId,
@RequestParam(value = "isInit", required = false) String isInit,
@RequestParam(value = "idToken", required = false) String idToken,
HttpServletRequest request, Model model) {
if (Objects.isNull(isInit)) {
return "s2013_chat";
}
ChatForm form = chatHelper.init(liffChannelId, messageChannelId, idToken, page, request);
return "s2013_chat";
}
And in my js:
$(document).ready(function () {
const urlParams = new URLSearchParams(window.location.search);
const isInit = urlParams.get("isInit");
if (!isInit) {
initLiffApp();
}
});
function initLiffApp() {
const messageChannelId = new URLSearchParams(window.location.search).get("messageChannelId");
if (!messageChannelId) {
alert("MessageChannelId is missing");
return;
}
const liffChannelId = new URLSearchParams(window.location.search).get("liffChannelId");
if (!liffChannelId) {
alert("LiffChannelId is missing");
return;
}
const liffId = new URLSearchParams(window.location.search).get("liffId");
if (!liffId) {
alert("LiffId is missing");
return;
}
liff
.init({
liffId: liffId
})
.then(() => {
const idToken = liff.getIDToken();
if (!idToken) {
alert("Failed to get ID Token");
return;
}
sendToServer(liffChannelId, messageChannelId, idToken);
})
.catch(err => {
console.error("LIFF init error", err);
});
}
function sendToServer(liffChannelId, messageChannelId, idToken) {
const redirectUrl = `/counseling/chat/client?liffChannelId=${encodeURIComponent(liffChannelId)}&messageChannelId=${encodeURIComponent(messageChannelId)}&isInit=1&idToken=${encodeURIComponent(idToken)}`;
window.location.href = redirectUrl;
}
When returning for the first time, in js make a call to the liff server to get idToken and at this time will call back to the server 1 more time with isInit is true. At this time the backend will start processing. However, when building on iOS, I noticed that when init for the first time, it returns the screen UI without displaying anything (I think it’s due to the processing when isInit is null, it returns without calling liff anymore).
I tried commenting out the isInit variable check, and now the UI is displayed but does not receive any css and js events.
//if (Objects.isNull(isInit)) {
// return "s2013_chat";
//}
I used Web Inspector on Safari browser to check and saw that the css and js files were loaded successfully, but the console log is reporting an error as shown.
Please help me with this problem, I have been trying to solve it for 3 days but still don’t know the reason why?