如何在 iOS 9 中从电子邮件 URL 打开应用程序?
How to open app from email URL in iOS 9?
我试过类似的方法:
在 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>
但是不起作用。我希望应用程序从我通过电子邮件发送的 link 打开,有人有想法让它工作吗?
对于未来的用户,正如@iSashok 在评论中提到的,handleOpenURL 函数is deprecated as of iOS 9。
对于 iOS 的较新版本,您需要使用以下函数 (Apple Docs):
optional func application(_ app: UIApplication,
open url: URL,
options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool
您将能够保持函数体与以前相同,现在它可以工作了。
我试过类似的方法:
在 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>
但是不起作用。我希望应用程序从我通过电子邮件发送的 link 打开,有人有想法让它工作吗?
对于未来的用户,正如@iSashok 在评论中提到的,handleOpenURL 函数is deprecated as of iOS 9。
对于 iOS 的较新版本,您需要使用以下函数 (Apple Docs):
optional func application(_ app: UIApplication,
open url: URL,
options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool
您将能够保持函数体与以前相同,现在它可以工作了。