ios - 我如何知道应用程序是否通过 AppDelegate didFinishLaunchingWithOptions 处的 Firebase-Deep Link(动态链接)启动

标签 ios swift firebase appdelegate deeplink

我们正在将 Firebase-Deeplinks 添加到我们的 IOS 项目中,以便可以通过深层链接启动该应用。

到目前为止,深度链接功能本身运行良好,默认的应用程序启动例程也是如此。但是让两个 startRoutines 并排工作让我有些头疼。

看看这段代码片段,我想要实现的目标就显而易见了。

func application(_:didFinishLaunchingWithOptions:) {
   FirebaseApp.configure()

   if "deeplink" {
      return true 
   }
   defaultAppLaunch() // no deeplink
   return true 
}

如果存在深层链接,将调用这些 appDelegate 函数之一:

func application(:continueUserActivity:restorationHandler:) {
    handleDeeplink()
    return true
}

func application(:openURL:options:) {
    handleDeeplink()
    return true  
}

那么我怎么知道 application(_:didFinishLaunchingWithOptions:) 是否可以调用 defaultAppLaunch()

我知道有 launchOptions-参数,但在我的例子中它总是nil,至少在通过 XCode 运行应用程序时是这样。并且 Firebase 文档也没有说明由 Firebase-Deeplinks 设置的 launchOptions。

非常感谢您的帮助。

最佳答案

长话短说

You can't know that your app was opened using deeplinks through App Delegate DidFinishLaunching.


解释:

无论应用是正常打开还是通过深层链接打开,总是调用应用委托(delegate)完成启动。所以你无法通过 app delegate 知道

相反,如果调用以下委托(delegate)函数,您可以知道应用程序是通过深度链接打开的。

func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
  if let dynamicLink = DynamicLinks.dynamicLinks().dynamicLink(fromCustomSchemeURL: url) {
    // Handle the deep link. For example, show the deep-linked content or
    // apply a promotional offer to the user's account.
    // ...
    return true
  }
  return false
}

并且您应该在同一个函数中处理深层链接功能

关于ios - 我如何知道应用程序是否通过 AppDelegate didFinishLaunchingWithOptions 处的 Firebase-Deep Link(动态链接)启动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52522971/

相关文章:

node.js - 获取用户 ID 后,Firebase 函数 onCreate 方法无法在 Firestore 上运行

ios - 尝试从下向上而不是自上而下为 UIView 高度设置动画

ios - 核心数据 - 不能存储两个单独的实体

ios - 使用 Swift 从底部向上推 View Controller

swift - WKInterfaceLabel 在组内时不会滚动

Angular 4 : How do I generate an XML file and return it to the browser

ios - UITabBar 图片不清晰

ios - 如何获取 iOS 移动配置文件的代码签名证书

ios - 确定您的应用程序之前是否在 iOS 中安装过

ios - 推送通知未收到 content_available