Finally, he started working using a “workaround”, which is not the general solution I originally hoped for:
I use the fact that the link I'm trying to open is a custom URL scheme (e.g. myxx: // localhost) on the mobile device, and if it fails, the action I want to perform is redirecting to the standard application URL (os-specific). The workaround is trying to open a custom URL, and if it doesn’t work, the timeout function starts shortly afterwards and opens an alternate URL:
setTimeout(function() { window.location=alternateUrl; }, 25); window.location = customUrl;
The downside is that when a customURL fails, the standard Safari browser displays a message box that the site cannot be opened, but at least it redirects the user to the AppStore.
source share