Detect if iOS app is installed in safari browser through javascript

Dear Team,


I am trying to add App Promotion to my website using Custom URL scheme with Javascript. If the App is installed on the device, it shows one popup of opening the app. But if app is not installed, i get a popup saying "Safari cannot open the page because the address is invalid".


Steps :- I have set the Custom url , lets say 'abcd'. And i am trying to open my app from javascript using - windows.location="abcd://"; The functionality is fine if the app is installed. But if the app is not installed, i get a popup stating - "safari cannot open the page because the address is invalid".


What is Required :- I want the user to see a popup before he/she goes to the App and have the the script on the html page to detect if an App is installed or not, without any Safari popup, which currently occurs when app is not installed.


Universal links are a nice way for app promotion and we have that in place, but in some application the link is opened in in-app browser (LinkedIn, Twitter), what if we want to show a popup on website, to open the content in App or not.


Here is the script we are trying to run on my website page-


if (/iPad|iPhone/.test(navigator.platform)) {

window.location = "abcd://" + url;

}


I request you to help me as I am stuck in this scenario from past few weeks. Kindly let me know if you need any other information from my side.

Replies

You can see how deep linking fallback is handled in this Stack Overflow post:
https://stackoverflow.com/questions/56528191/how-to-fix-deep-linking-in-ios-when-the-application-has-not-installed-in-the-dev