简体   繁体   English

iOS:如果应用程序未打开,苹果通用链接?

[英]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.

相关问题 通用链接无法在iOS上打开应用 - Universal link doesn't open the app on iOS iOS通用链接:如果未安装应用,则打开商店链接 - Universal links iOS : open store link if app NOT installed 在iOS 9 Safari中粘贴通用链接,但应用不会自动打开 - Paste universal link in iOS 9 safari, but app does not open automatically 从UIWebView中的链接打开iOS6 Apple Maps应用程序 - Open iOS6 Apple Maps app from a link in a UIWebView 使用Apple Universal Linking强制打开应用程序 - Force open app using Apple Universal Linking 通用链接未在iOS 9中的应用中打开 - Universal Link is not opening in app in iOS 9 iOS:Apple Universal Link continueUserActivity方法如果未安装应用程序则不会调用? - iOS: Apple Universal Link continueUserActivity method doesn't call if the app is not installed? 使用通用链接在 iOS 上打开 Google 地图地点 - Open Google Maps place on iOS with Universal Link 如果设备上安装的iOS通用链接上有多个受支持的应用程序,是否可以选择每次打开的应用程序? - Is it possible to choose the app to open every-time if there are multiple supported app on the iOS universal link installed on device? 通用链接始终打开应用程序,无论 Apple 应用程序站点关联如何 - Universal link always opens app regardless of Apple App Site Associations
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM