[英]Open url from Today Extension
I'm trying to open a deep link from my today extension widget to my main app with no luck. 我正试图从我今天的扩展小部件打开一个深层链接到我的主应用程序,没有运气。
//ExtensionViewController.swift
public func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
let url = URL(string: "ACTION_TODAY://")
self.extensionContext?.open(url!, completionHandler: { (completed) in
})
}
Info.plist of the main app : (I guess ACTION_TODAY://
is not needed, but ACTION_TODAY
alone gives me the same result) 主app的Info.plist :(我猜ACTION_TODAY://
不需要,但ACTION_TODAY
单独给我相同的结果)
//AppDelegate.swift
func application(_ application: UIApplication, open url: URL,
sourceApplication: String?, annotation: Any) -> Bool {
let action_today = "ACTION_TODAY://"
if url.absoluteString.contains(action_today) {
return true
}
return false
}
func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
let action_today = "ACTION_TODAY://"
if url.absoluteString.contains(action_today) {
return true
}
return false
}
When I select one of the item of the collectionView displayed in the today extension, the console gives me a __55-[_NCWidgetExtensionContext openURL:completionHandler:]_block_invoke failed: Error Domain=NSOSStatusErrorDomain Code=-50 "(null)"
当我选择今天扩展中显示的collectionView项之一时,控制台给我一个__55-[_NCWidgetExtensionContext openURL:completionHandler:]_block_invoke failed: Error Domain=NSOSStatusErrorDomain Code=-50 "(null)"
In today view controller, put the following code where you need to open the main iOS app from the extension. 在今天的视图控制器中,将以下代码放在需要从扩展程序打开主iOS应用程序的位置。
let appURL = NSURL(string: "StarterApplication://") self.extensionContext?.open(appURL! as URL, completionHandler:nil)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.