我正在开发iOS应用的通用链接实现。
这是我的一小部分AppDelegate:
private func application(_ application: UIApplication, openURL url: URL, sourceApplication: String?, annotation: AnyObject) -> Bool {
DeepLinkHelpers.handleUniversalLink(url.absoluteString)
return true
}
private func application(application: UIApplication, continueUserActivity userActivity: NSUserActivity, restorationHandler: ([AnyObject]?) -> Void) -> Bool {
DeepLinkHelpers.handleUniversalLink(userActivity.webpageURL?.absoluteString)
return true
}
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
signalRConnector.launch()
NotificationCenter.default.addObserver(self, selector: #selector(AppDelegate.processRestartSignalRNotification(_:)), name: NSNotification.Name(rawValue: "restartSignalR"), object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(AppDelegate.reachabilityChanged(_:)),
name: ReachabilityChangedNotification,
object: reachability)
do {
try reachability.startNotifier()
} catch {
Logger.save(text: "Unable to start notifier")
}
return true
}
我已经处理了通用链接集成的所有其他步骤:
我正在做以下调试:
根据文档,应该执行continueUserActivity。当应用程序在后台运行且应用程序未运行时,它不会同时执行。
提前谢谢!任何帮助表示赞赏。
答案 0 :(得分:5)
从iOS 12,Swift 4.2和Xcode 10开始,Apple再次将方法签名(restoreHandler的类型)更改为
func application(_ application: UIApplication, continue userActivity:
NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
答案 1 :(得分:0)
我怀疑这是因为您已将continueUserActivity
功能标记为private
。我从未见过这一点,事实上,当我尝试时,Swift 3实际上会出错。似乎没有任何以on all of GitHub方式构建的代码示例。
我建议删除private
范围。
答案 2 :(得分:0)
在2019年,这对我有所帮助(来自本指南:SHGetKnownFolderPath()
):
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([Any]?) -> Void) -> Bool {
print("Continue User Activity called: ")
if userActivity.activityType == NSUserActivityTypeBrowsingWeb {
let url = userActivity.webpageURL!
print(url.absoluteString)
//handle url and open whatever page you want to open.
}
return true
}