iOS:如果应用未打开,苹果通用链接? [英] iOS: apple universal link if app is not open?

查看:124
本文介绍了iOS:如果应用未打开,苹果通用链接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果该应用程序已经打开(后台),则我的应用程序可以成功处理Apple通用链接.但是,如果该应用程序尚未打开,那么当我在邮件中点击这样的链接时,该应用程序将打开,但我永远都不会收到application:continueUserActivity ...的回调(如果该应用程序已经打开,则会执行此操作/背景)...

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)...

智慧:

如果该应用程序是后台运行的,而我在邮件应用程序中单击了一个苹果通用链接,则使用此方法(这是苹果公司的文档所说的用来处理通用链接的方法):

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?

基于MCMatan的线索,您必须在didFinishLaunchingWithOptions中执行类似的操作,然后将调用continentUserActivity:

Based MCMatan's clue, you have to do something like this in didFinishLaunchingWithOptions, and then continueUserActivity will get called:

if let userActivityDict = launchOptions?[UIApplicationLaunchOptionsUserActivityDictionaryKey] as? NSDictionary,
      activityType = userActivityDict[UIApplicationLaunchOptionsUserActivityTypeKey] as? String where activityType == NSUserActivityTypeBrowsingWeb {

    return true
}

推荐答案

您是正确的.如果应用程序不在后台,则不会调用"continueUserActivity".

You are correct. If the app is not in background "continueUserActivity" will not be called.

相反,application:didFinishLaunchingWithOptions会调用以下信息:

Instead, application:didFinishLaunchingWithOptions will call with the information:

let activityDic = launchOptions?[UIApplicationLaunchOptionsUserActivityDictionaryKey]
if let isActivityDic = activityDic {
    // Continue activity here
}

这篇关于iOS:如果应用未打开,苹果通用链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆