如何从iOS 9中的电子邮件URL打开应用程序?

时间:2016-09-07 13:44:27

标签: ios swift swift2 ios9

我尝试过类似的事情:

在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
}

在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>

但是不起作用。我希望通过电子邮件发送的链接打开应用程序,任何人都有想法让它工作吗?

1 个答案:

答案 0 :(得分:0)

对于未来的用户,如评论中提到的@iSashok,handleOpenURL函数is deprecated as of iOS 9

对于较新版本的iOS,您需要使用以下功能(Apple Docs):

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

你将能够像以前一样保持功能的主体,现在它可以工作。