打开iOS应用后,"continue userActivity:"方法未调用-Firebase动态链接 [英] After opening iOS app "continue userActivity:" method isn't called - Firebase dynamic link

查看:1455
本文介绍了打开iOS应用后,"continue userActivity:"方法未调用-Firebase动态链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经成功集成了Firebase动态链接,当我单击动态链接时,我的应用程序正在打开.

我面临的问题是从动态链接打开应用程序后,应该调用continue userActivity:方法,但是什么也没发生.

我已经检查了所有可能的东西,但没有发现问题.

我已经在SO中搜索了此内容,但没有一个答案对我有帮助.

我的代码:

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
}

解决方案

Google的失误.

我不知道他们是否保留文档.是否最新.

我刚刚复制了Google官方Firebase动态链接文档中的代码.

为什么未调用continue userActivity:方法?

原因是(请参见以下方法中的区别)

从Google文档粘贴的副本. -错误的

func应用程序(_应用程序:UIApplication,继续userActivity:NSUserActivity,restoreHandler:@escaping([< UIUserActivityRestoring ]?)->无效)->布尔{

}

我写了这篇文章(没有从Google文档粘贴粘贴)-更正了

func应用程序(_应用程序:UIApplication,继续userActivity:NSUserActivity,restoreHandler:@逃逸([ 任何 ]?)->无效)-> Bool {

}

我已经加粗了区别.

这是我尝试了多个小时的内容.盲目地信任Google文档对我来说真的很沮丧:-|

希望这可能对其他人有帮助.

I have successfully integrated Firebase dynamic links and when I click on dynamic link then my app is opening.

The issues I'm facing is after opening app from dynamic links, continue userActivity: method should be called, but nothing happens.

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.

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
}

解决方案

The blunder of Google.

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.

Why was the continue userActivity: method is not called?

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 {

}

I wrote this (without copy paste from google doc.) - Correct one

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.

这篇关于打开iOS应用后,"continue userActivity:"方法未调用-Firebase动态链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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