iOS9 redirect to url scheme if app installed

I have created a landing page in my webapp that will attempt to redirect to my native app's URL scheme if the app is installed and if it is not, I have a timeout set to redirect to the normal webapp URL as discussed here.


My code looks like this:


$(document).ready(function() { 
     window.location.href = "urlScheme://";
      setTimeout(function() { 
          window.location.href = "http://foo.bar/webappurl"
     }, 500); 
})


The app redirects to 'http://foo.bar/webappurl' no matter what, even when the app is installed. I can see the "do you want to open this in your app?" dialog for a split second before it redirects, but it always redirects no matter what.

Can anyone tell me what I'm doing wrong here or recommed a better way to check to see if the app is installed and then redirect there using Javascript?

iOS9 redirect to url scheme if app installed
 
 
Q