javascript - iOS9: Try to open app via scheme if possible, or redirect to app store otherwise -
my question ios9 only!
i have html
landing page, , try redirect user to app via url scheme if app installed, or redirect appstore otherwise.
my code is:
document.addeventlistener("domcontentloaded", function(event) { var body = document.getelementsbytagname('body')[0]; body.onclick = function () { openapp(); }; }); var timeout; function preventpopup() { cleartimeout(timeout); timeout = null; window.removeeventlistener('pagehide', preventpopup); } function openapp(appinstanceid, platform) { window.addeventlistener('pagehide', preventpopup); document.addeventlistener('pagehide', preventpopup); // create iframe var iframe = document.createelement("iframe"); document.body.appendchild(iframe); iframe.setattribute("style", "display:none;"); iframe.src = 'myscheme://launch?var=val'; var timeouttime = 1000; timeout = settimeout(function () { document.location = 'https://itunes.apple.com/app/my-app'; }, timeouttime); }
the problem iframe
trick doesn't work in safari
ios9
.
any idea why?
my iframe
trick based on this answer.
the iframe trick no longer works -- guess apple knows encourage more developers implement universal links, more quickly.
you can still set window.location='your-uri-scheme://';
, fallback app store after 500ms. there "dance" between popups if take approach, @ branch (we fallback if universal links don't work).
window.location = 'your-uri-scheme://'; // result in error message if app not installed settimeout(function() { // link app store should go here -- fires if deep link fails window.location = "https://itunes.apple.com/us/app/myapp/id123456789?ls=1&mt=8"; }, 500);
i wish had better answer you. ios 9 more limited.
for helpful overview of what's needed universal links should go route, check out answer here or read tutorial
Comments
Post a Comment