Jhony  Blaze Jhony Blaze - 2 months ago 19
Swift Question

How to open app from email URL in iOS 9?

I've tried something like:

In the AppDelegate:

func application(application: UIApplication, handleOpenURL url: NSURL) -> Bool {
var returnValue = false
let urlString = url.absoluteString
print(urlString)
if(urlString.hasPrefix("")){
returnValue = true
}
return returnValue
}


In the info.plist

<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLName</key>
<string>co.example.ExampleApp</string>
<key>CFBundleURLSchemes</key>
<array>
<string>example</string>
</array>
</dict>
</array>


But doesn't work. I want the app opens from a link that I send via email, anyone has an idea to make it work?

Answer

For future users, as @iSashok mentioned in the comments, the handleOpenURL function is deprecated as of iOS 9.

For newer versions of iOS you need to use the following function (Apple Docs):

optional func application(_ app: UIApplication, 
                 open url: URL, 
              options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool

You'll be able to keep the body of the function the same as before, and now it will work.