I am using the below code to detect my app in mobile phone and the code works fine on chrome(for both android and IOS). But in case of safari the issue is when my function is called it causes a popup to open when app is installed and the popup as to open the app or cancel(two buttons). when i click open app within the specified time (2s). it opens the app but when i click the open app after 2s it opens the app and app store link as well. Also, when i click the cancel it also takes me to the app store
`
OpenToolKit() {
let ua = navigator.userAgent.toLowerCase();
let isAndroid = /android|tab|touch|webOS|tablet|mobile/i.test(ua) || navigator.maxTouchPoints > 0; // android check
let isIphone = ua.indexOf("iphone") > -1 || ua.indexOf("ipad") > -1; ; // ios check
function openApp(url, appStoreUrl) {
let isAppOpened = false;
window.location.href = url; // Attempt to open the app using the custom URL scheme
setTimeout(() => {
isAppOpened = document.hidden || document["webkitHidden"];
}, 500);
setTimeout(() => {
if (!isAppOpened) {
window.location.href = appStoreUrl;
}
}, 2500);
document.addEventListener('visibilitychange', function () {
if (document.hidden || document["webkitHidden"]) {
isAppOpened = true;
}
});
}
if (isIphone) {
openApp(URLs, 'https://apps.apple.com/us/app/my-app');
} else if (isAndroid) {
openApp(URLs, 'https://play.google.com/store/apps/details);
}
}