且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

打开iOS应用后,"continue userActivity:"方法未调用-Firebase动态链接

更新时间:2023-01-01 17:26:54

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.