4

I am using the following piece of code for launching my app from safari. What I want is, when a user clicks on the link from safari, it will launch my app, and If the app is not installed in device, safari will redirect to the iTunes link of that particular app.

   setTimeout(function() {
  window.location = "http://itunes.com/apps/myappname";
}, 25);

// If "custom-uri://" is registered the app will launch immediately and your
// timer won't fire. If it's not set, you'll get an ugly "Cannot Open Page"
// dialogue prior to the App Store application launching
window.location = "custom-uri://";

Everything is working fine, except safari showing an error alert before redirecting to the iTunes link (if the app is not installed in device).

"Safari cannot open this page, because the address is invalid".

As it is a bad user experience, is there any way that I can suppress or avoid this popup before redirecting to the iTunes link.?

AloSwift
  • 407
  • 6
  • 24
  • [Check this](http://stackoverflow.com/questions/1108693/is-it-possible-to-register-a-httpdomain-based-url-scheme-for-iphone-apps-like/1109200#1109200), may be its the same what you are asking. – Janak Nirmal May 27 '14 at 04:57
  • Did you handle custom-uri:// in you app? Check out the tutorial :http://kotikan.com/blog/posts/2011/03/passing-data-between-ios-apps – Velmurugan S May 27 '14 at 05:06
  • 1
    Approach was good, Method also working but i dont think you can avoid native alert. – Nitin Gohel May 27 '14 at 05:11
  • @VelmuruganS As of now for testing purpose am using the urlscheme of skype. And yea I have gone through the tutorials of custom url. Safari error is the only issue that I am facing. – AloSwift May 27 '14 at 05:19
  • issue is that your url is not correct. that you are using – Nitin Gohel May 27 '14 at 05:22
  • 1
    Actually, issue is that, if I want to open skyep and same is not installed,the url "skype:" will be unknown to safari. So it will show that error and then redirects to the iTunes link. So i want to avoid that alert pop. Safari should redirect to the iTunes link without showing any error. – AloSwift May 27 '14 at 05:27
  • $.ajax({ type: 'POST', url: 'example://', complete: function (transport) { if (transport.status == 200) { alert('Success'); } else { alert(transport.status); alert('Failed'); } } }); check this way. may helpfull – Velmurugan S May 27 '14 at 05:39
  • 1
    Its not working. Ajax is not responding to custom url – AloSwift May 27 '14 at 05:43
  • Just try this url:http://stackoverflow.com/questions/358397/javascript-to-detect-skype/358553#358553 – Velmurugan S May 27 '14 at 05:50

2 Answers2

0

You can open the app through iframe to suppress mobile safari "invalid address" warnings. This code works for me: https://gist.github.com/zengfenfei/51b36c008faaea4cb934

Kevin
  • 300
  • 1
  • 12
0

I am still using uri schemes redirects from my website to my app. Tested on iOS 10 through 14 (no guarantee how long it will continue to work though). My implementation is built upon others but helps managed left over blank tabs the user no longer needs in their browser:

https://stackoverflow.com/a/68653745/2036221

rolinger
  • 2,787
  • 1
  • 31
  • 53