Given: Website, iOS and Android applications, registered urlscheme \"myapp://\".
Goal: on the website have a link shown to iOS/Android devices with app installed. Cl
So the way it works on ios without always opening the store when the app is installed is to do something like this:
function isIOS() {
const iDevices = [
'iPad Simulator',
'iPhone Simulator',
'iPod Simulator',
'iPad',
'iPhone',
'iPod'
];
if (navigator.platform) {
while (iDevices.length) {
if (navigator.platform === iDevices.pop()) {
return true;
}
}
}
return false;
}
let openedApp = false;
function openAppOrStore() {
setTimeout(function () {
if (!openedApp) {
window.location = "https://apps.apple.com/us/app/petleo/id1462882016";
}
}, 25);
const parts = window.location.href.split('/');
const consultationId = parts[parts.length - 2];
const iosLink = "petleo://consultations/" + consultationId;
try {
window.location = iosLink;
if (window.location.href.indexOf("petleo://") !== -1) {
openedApp = true;
}
} catch (e) {
}
}
setTimeout(function () {
if (window.location.href.indexOf('consultation') !== -1) {
if (isIOS()) {
openAppOrStore();
}
}
}, 25);