Reputation: 3604
I need to be able to launch my iOS app from the Safari browser. So I went to my .plist
file in xcode and added an item to my URL Schemes and entered in the string of myappname
.
Now if I go to Safari, and type myappname://
in the URL address bar and submit it, it shows me a UIAlertView
that says Open this page in "MyAppName"?
with options for Cancel
and Open
.
If I tap Open
it successfully opens my app, however I want to do this without the UIAlertView
popping up with that message.
I have done some quick searching online and it looks like people keep having trouble with this whenever a new iOS update comes out and I can't seem to find a recent solution or answer.
I am on an iPhone 4s with iOS 7.1, and I'm using xcode 5.1 if that makes any difference.
Also, I have been using an app available in the App Store called "Frontback" that successfully does this same thing without the UIAlertView
showing in Safari so this is definitely possible.
Thanks for the help.
Upvotes: 10
Views: 5208
Reputation: 525
Here is how to avoid the "Open this page in YourAppName?" popup when using Universal links.
My observation is as follows:
window.location.href
or window.location.replace
to directly get back to the app without the user needing to click a link then it seems to depend on if is there is a delay before the redirect. If the page loads fast and you directly call window.location.replace
then the popup will appear. However if you set a timeout to 400ms and then trigger window.location.replace
then there will be no popup.I found this when noticing that after a change and redeployment of the html page, the popup was not shown. This was the case for me because I use a cloudflare worker to host the html page and after an update the initial response time is about 400ms while it is just 15ms if requested again.
Upvotes: 0
Reputation: 80
I use this method in my app without getting a UIAlertView
. It just goes straight to the app.
I had a similar issue when I first started implementing it. I suspect that it's not a problem with myappname://
, but possibly a problem with how you added the URL Scheme.
Make sure to assign your custom value (myappname
) to the URL Identifier
object (com.mycompany.myappname
). The URL identifier
should be a String and the URL Schemes
should be an array with your custom value being a String.
The XML version of your .plist should look like this:
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLName</key>
<string>com.mycompany.myappname</string>
<key>CFBundleURLSchemes</key>
<array>
<string>myappname</string>
</array>
</dict>
</array>
Upvotes: 2