ios - 我如何知道应用程序是否通过 AppDelegate 的 didFinishLaunchingWithOptions 的 Firebase-Deeplink(动态链接)启动
问题描述
我们正在将 Firebase-Deeplinks 添加到我们的 IOS 项目中,以便可以通过深度链接启动应用程序。
到目前为止,深度链接功能本身运行良好,默认应用程序启动例程也是如此。但是让两个 startRoutines 并排工作让我有些头疼。
我想要实现的目标很明显,看看这个代码片段。
func application(_:didFinishLaunchingWithOptions:) {
FirebaseApp.configure()
if "deeplink" {
return true
}
defaultAppLaunch() // no deeplink
return true
}
如果存在深层链接,则调用这些 appDelegate-functions 之一:
func application(:continueUserActivity:restorationHandler:) {
handleDeeplink()
return true
}
func application(:openURL:options:) {
handleDeeplink()
return true
}
那么我怎么知道 application(_:didFinishLaunchingWithOptions:) 是否可以调用defaultAppLaunch()?
我知道有launchOptions -Argument 但在我的情况下它总是nil,至少在通过 XCode 运行应用程序时是这样。Firebase-Documentation 也没有说明由 Firebase-Deeplinks 设置的 launchOptions。
高度赞赏帮助。
解决方案
TL;博士
您无法知道您的应用是通过 App Delegate DidFinishLaunching 使用深层链接打开的。
解释:
无论应用程序是正常打开还是通过深层链接打开,始终会调用应用程序委托确实完成启动。所以你不能通过应用委托知道
相反,如果调用以下委托函数,您可以知道应用程序是通过深层链接打开的。
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
}
你应该在同一个函数中处理深层链接功能
推荐阅读
- python - Python scipy.optimize.fsolve 找到第一个交点
- node.js - 在 Node 上获取带有标题的 SVG 文本的宽度
- ios - 无法在 SwiftUI 中关闭模式
- ios - Xcode XCTest 使用异步队列测量性能
- r - 在观察事件中访问服务器端数据表
- c++ - 查找用户给定范围内所有数字的平均值
- flutter - 如何使用颤振小黄瓜在系统键盘上按 Enter 键?
- c# - EF Core - 当我指定自己的外键时会自动添加不需要的外键
- firebase - 如何将 Firebase 中的集合转换为字符串列表并使用它创建一些条件
- kubectl - kubectl 返回“无法连接到服务器:x509:证书对...有效”