简体   繁体   English

打开 iOS 应用程序后“continue userActivity:”方法未被调用 - Firebase 动态链接

[英]After opening iOS app "continue userActivity:" method isn't called - Firebase dynamic link

I have successfully integrated Firebase dynamic links and when I click on dynamic link then my app is opening.我已经成功集成了 Firebase 动态链接,当我点击动态链接时,我的应用程序就会打开。

The issues I'm facing is after opening app from dynamic links, continue userActivity: method should be called, but nothing happens.我面临的问题是从动态链接打开应用程序后, continue userActivity:应该调用方法,但没有任何反应。

I've checked the all the possible thing but didn't recognised the issue.我已经检查了所有可能的事情,但没有意识到这个问题。

I've searched the SO for this but none of the answer helped me.我为此搜索了 SO,但没有一个答案对我有帮助。

My Code:我的代码:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

  GIDSignIn.sharedInstance().clientID = kGoogleSignInClientId
  FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)

 // DynamicLinks.performDiagnostics(completion: nil)

  FirebaseApp.configure()

  return true
}

func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {

  if url.absoluteString.contains(kFBAppId) {

    return FBSDKApplicationDelegate.sharedInstance().application(app, open: url, options: options)

  }

  if let dynamicLink = DynamicLinks.dynamicLinks().dynamicLink(fromCustomSchemeURL: url) {
    print(dynamicLink.url ?? URL(string: "test") as Any)
    return true
  }

    return GIDSignIn.sharedInstance().handle(url, sourceApplication: options[.sourceApplication] as? String, annotation: options[.annotation])

}

func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {

  //This method is not getting called
}

I don't know whether they keep their doc.我不知道他们是否保留他们的文件。 up to date or not.是否最新。

I have just copy-pasted the code from the Google's official Firebase dynamic link document.我刚刚从 Google 的官方 Firebase 动态链接文档中复制粘贴了代码。

Why was the continue userActivity: method is not called?为什么continue userActivity:方法没有被调用?

The reason is (See the difference in following method)原因是(看下面方法的区别)

Copy pasted from google doc.从谷歌文档复制粘贴。 - Wrong one - 错了一个

func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([ UIUserActivityRestoring ]?) -> Void) -> Bool { func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([ UIUserActivityRestoring ]?) -> Void) -> Bool {

} }

I wrote this (without copy paste from google doc.) - Correct one我写了这个(没有从谷歌文档复制粘贴。) - 正确的

func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([ Any ]?) -> Void) -> Bool { func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([ Any ]?) -> Void) -> Bool {

} }

I've made bold the difference.我已经大胆地改变了。

This is what I was trying for many hours.这就是我尝试了好几个小时的方法。 It is really very frustrating for me to blindly trust on google doc.:-|盲目信任谷歌文档对我来说真的很令人沮丧。:-|

Hope this may help other.希望这可以帮助其他人。

Additional answer for those using separate SceneDelegate.swift apart from AppDelegate.swift: This method in AppDelegate >对于那些使用 AppDelegate.swift 之外的单独 SceneDelegate.swift 的人的附加答案:AppDelegate 中的此方法 >

func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
    if userActivity.activityType == CSSearchableItemActionType {

}

is now in SceneDelegate >现在在 SceneDelegate >

func scene(_ scene: UIScene, continue userActivity: NSUserActivity) {

}

To handle universal link in your application first you have to add an entitlement file with supported urls in your application. 要在应用程序中处理通用链接,首先必须在应用程序中添加包含受支持URL的授权文件。

To do so open Xcode, Select your project, Goto Capabilities and find Associated Domain section. 为此,请打开Xcode,选择您的项目,转到功能,然后找到关联域部分。

在此处输入图片说明

Turn on this capability and add an entry for each domain your app supports with a prefix of applinks: 启用此功能,并为您的应用程序支持的每个域添加一个带有应用程序链接前缀的条目:

Now you have to implement application(_:continue:restorationHandler:) in your AppDelegate file. 现在,您必须在AppDelegate文件中实现application(_:continue:restorationHandler :)。 This method will be called when user click on link which your supports. 当用户单击您支持的链接时,将调用此方法。

You need to check two times.你需要检查两次。

  1. When app.当应用程序。 is running in the background and is opening from Link: Delegate method is: func checkForTransferedTicket(_ userActivity: NSUserActivity) { }在后台运行并从链接打开:委托方法是: func checkForTransferedTicket(_ userActivity: NSUserActivity) { }

  2. When app.当应用程序。 is NOT running in background and is opening from Link:不是在后台运行,而是从链接打开:

     func scene(_ scene: UIScene, willConnectTo session: UISceneSession,options connectionOptions: UIScene.ConnectionOptions) { if let userActivity = connectionOptions.userActivities.first { print(userActivity) } }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Firebase 动态链接打不开app iOS - Firebase dynamic link not opening the app iOS 我们可以在第一次使用 Firebase 动态链接安装应用程序后检索动态 URL 吗? 如果是,那么如何? (斯威夫特/iOS) - Can we retrieve the Dynamic URL after the first time app installation using Firebase Dynamic Link? if yes, then how? (Swift/iOS) Firebase 动态链接在 IOS 上不起作用 - Firebase dynamic link is not working on IOS Firebase & iOS 14 > 动态链接跟踪和活动会继续有效吗? - Firebase & iOS 14 > Will dynamic links tracking and campaigns continue to work? Flutter iOS Firebase 带链接值的动态链接推送命名页面 - Flutter iOS Firebase dynamic link push named page with the link value 通过 Safari 打开时,Firebase 动态链接不会重定向到应用程序 - Firebase Dynamic Link doesn't redirect to the app when open through Safari 无法获取 Firebase 动态链接 - Can't get Firebase Dynamic Link 安装后我们无法从 Play 商店打开应用程序,动态链接 (firebase) Android 会发生这种情况 - we can't open apps from play store after an install, this happens with dynamic link (firebase) Android 在 iOS 上添加 firebase 动态链接 flutter package 后,应用程序在启动时关闭 - app close at the launch after add firebase dynamics link flutter package on iOS iOS 在应用程序处于非活动状态时处理动态链接 - iOS handle dynamic link while app is inactive
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM