[英]iOS: apple universal link if app is not open?
My app can successfully handle apple universal links, if the app is already open (backgrounded).如果应用程序已经打开(背景),我的应用程序可以成功处理苹果通用链接。 But if the app is not open already, then when I tap such a link in, say, mail, the app opens, but I never get the callback for application:continueUserActivity... (which I do if the app was already open/backgrounded)...但是,如果应用程序尚未打开,那么当我点击这样的链接时,例如,邮件,应用程序打开,但我永远不会收到 application:continueUserActivity 的回调......(如果应用程序已经打开,我会这样做/有背景)...
To wit:即:
If the app is backgrounded, and I click on an apple universal link in, say, the mail app, then this method (which is what apple's documentation says to implement to handle universal links):如果应用程序是后台的,并且我点击了一个苹果通用链接,比如说邮件应用程序,那么这个方法(这是苹果的文档所说的用于处理通用链接的实现):
optional func application(_ application: UIApplication,
continueUserActivity userActivity: NSUserActivity,
restorationHandler restorationHandler: ([AnyObject]?) -> Void) -> Bool
Gets called.被调用。 If the app is not running (I force close it), then when I click on the link, that method does NOT get called, but the app DOES open.如果应用程序没有运行(我强制关闭它),那么当我点击链接时,该方法不会被调用,但应用程序会打开。
Is this supposed to work this way?这应该以这种方式工作吗?
Based MCMatan's clue, you have to do something like this in didFinishLaunchingWithOptions, and then continueUserActivity will get called:根据 MCMatan 的线索,你必须在 didFinishLaunchingWithOptions 中做这样的事情,然后 continueUserActivity 将被调用:
if let userActivityDict = launchOptions?[UIApplicationLaunchOptionsUserActivityDictionaryKey] as? NSDictionary,
activityType = userActivityDict[UIApplicationLaunchOptionsUserActivityTypeKey] as? String where activityType == NSUserActivityTypeBrowsingWeb {
return true
}
You are correct.你是对的。 If the app is not in background "continueUserActivity" will not be called.如果应用程序不在后台,则不会调用“continueUserActivity”。
Instead, application:didFinishLaunchingWithOptions
will call with the information:相反, application:didFinishLaunchingWithOptions
将使用以下信息调用:
let activityDic = launchOptions?[UIApplicationLaunchOptionsUserActivityDictionaryKey]
if let isActivityDic = activityDic {
// Continue activity here
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.