[英]How do I know if app was launched via Firebase-Deeplink (Dynamic Links) at AppDelegate's didFinishLaunchingWithOptions
We are adding Firebase-Deeplinks to our IOS-project, so that the app can be started via deeplink. 我们正在将Firebase-Deeplinks添加到我们的IOS项目中,以便可以通过Deeplink启动该应用程序。
The deeplink-feature itself work fine so far, and so does the default app launch routine. 到目前为止,deeplink功能本身可以正常工作,默认的应用启动例程也可以正常工作。 But making both startRoutines work side by side gives me some headache.
但是让两个startRoutines一起工作会使我有些头疼。
What I am trying to achieve get's obvious looking at this code snippet. 我正在尝试实现的目标很明显地看了一下这段代码。
func application(_:didFinishLaunchingWithOptions:) {
FirebaseApp.configure()
if "deeplink" {
return true
}
defaultAppLaunch() // no deeplink
return true
}
If there is a deeplink one of these appDelegate-functions is called: 如果存在深层链接,则将这些appDelegate函数之一称为:
func application(:continueUserActivity:restorationHandler:) {
handleDeeplink()
return true
}
func application(:openURL:options:) {
handleDeeplink()
return true
}
So how do I know at application(_:didFinishLaunchingWithOptions:) if I can call defaultAppLaunch() ? 那么我如何知道application(_:didFinishLaunchingWithOptions :)是否可以调用defaultAppLaunch() ?
I know there is the launchOptions -Argument in but in my case it is always nil , at least when running the app via XCode. 我知道其中包含launchOptions -Argument,但就我而言,它始终为nil ,至少在通过XCode运行应用程序时如此。 And also the Firebase-Documentation says nothing about launchOptions to be set by Firebase-Deeplinks.
而且,Firebase文档对由Firebase-Deeplinks设置的launchOptions没有任何说明。
Help is highly appreciated. 非常感谢您的帮助。
I'm referencing the Firebase docs in handling dynamic links for iOS: Firebase docs for receiving dynamic links 我在处理iOS的动态链接时引用了Firebase文档: 用于接收动态链接的Firebase文档
Next, in the application:continueUserActivity:restorationHandler: method, handle links received as Universal Links when the app is already installed (on iOS 9 and newer):
接下来,在application:continueUserActivity:restorationHandler:方法中,处理已安装应用程序(在iOS 9及更高版本上)作为通用链接接收的链接:
func application(_ application: UIApplication, continue userActivity: NSUserActivity,
restorationHandler: @escaping ([Any]?) -> Void) -> Bool {
let handled = DynamicLinks.dynamicLinks().handleUniversalLink(userActivity.webpageURL!) { (dynamiclink, error) in
// ...
}
return handled
}
Finally, in the application:openURL:sourceApplication:annotation: (iOS 8 and older) and application:openURL:options: (iOS 9 and up) methods, handle links received through your app's custom URL scheme.
最后,在application:openURL:sourceApplication:annotation:(iOS 8及更高版本)和application:openURL:options:(iOS 9及更高版本)方法中,处理通过应用程序的自定义URL方案接收的链接。 These methods are called when your app receives a link on iOS 8 and older, and when your app is opened for the first time after installation on any version of iOS.
当您的应用在iOS 8和更早版本上收到链接时,以及在任何版本的iOS上安装后首次打开应用时,都会调用这些方法。
@available(iOS 9.0, *)
func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any]) -> Bool {
return application(app, open: url,
sourceApplication: options[UIApplicationOpenURLOptionsKey.sourceApplication] as? String,
annotation: "")
}
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
}
But you did mention that the app is currently only being run on Xcode (and I'm guessing iOS Simulator, maybe you can try it on a test device too!) 但是您确实提到了该应用程序当前仅在Xcode上运行(我猜是iOS模拟器,也许您也可以在测试设备上尝试它!)
You can't know that your app was opened using deeplinks through App Delegate DidFinishLaunching.
您不知道您的应用是通过App Delegate DidFinishLaunching使用深层链接打开的。
App delegate did finish launch is always called, regardless if app was opened normally or via deeplinks. 无论应用程序是正常打开还是通过深度链接打开, 始终会调用完成的启动的应用程序委托。 so you can't know through app delegate
因此您无法通过应用委托了解
Instead, you can know that app was opened through deeplinks if the following delegate function is called. 相反,如果调用以下委托函数,则可以知道该应用是通过深层链接打开的。
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
}
and you should handle the deeplinks functionality in the same function 并且您应该在同一函数中处理Deeplinks功能
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.