Firebase Deeplink在Swift 3中未调用AppDelegate的application:continueUserActivity:restorationHandler函数 [英] Firebase Deeplink not calling application:continueUserActivity:restorationHandler function of AppDelegate in Swift 3
问题描述
我正在使用Firebase Deeplink URL打开应用程序的特定部分。当应用程序在后台运行时,它运行良好,但是当我终止了该应用程序并从外部单击Deeplink url而不是我不知道如何处理这种情况时,我的意思是我应该写条件以获得url参数。
I am using firebase Deeplink URL to open my app's specific section. It is working well when app running in background but when I killed the app and click deeplink url from outside than I don't know how to handle that case, I mean where I should write my condition to get the parameters of url.
这种应用程序委托的方法是在后台运行应用程序时调用的
This method of app delegate called when app in background
@available(iOS 8.0, *)
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([Any]?) -> Void) -> Bool {
guard let dynamicLinks = DynamicLinks.dynamicLinks() else {
return false
}
let handled = dynamicLinks.handleUniversalLink(userActivity.webpageURL!) { (dynamiclink, error) in
if let dynamicLink = dynamiclink, let _ = dynamicLink.url
{
var path = dynamiclink?.url?.path
path?.remove(at: (path?.startIndex)!)
let delimiter = "/"
var fullNameArr = path?.components(separatedBy: delimiter)
let type: String = fullNameArr![0]
let Id: String? = (fullNameArr?.count)! > 1 ? fullNameArr?[1] : nil
if(type == "games")
{
self.callGameDetailView(gameId: Id! , gameType: "created", notificationId: "NIL" )
}else{
var paths = dynamicLink.url?.path
paths?.remove(at: (path?.startIndex)!)
self.setRewardViewController(paths!)
}
} else {
// Check for errors
}
}
return handled
}
,但是当我杀死应用程序并点击动态链接URL时,它不会调用open url方法: / p>
but it will not call open url method when I killed the app and hit the dynamic link url:
@available(iOS 9.0, *)
func application(_ application: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any])
-> Bool {
return self.application(application, open: url, sourceApplication: nil, annotation: [:])
}
func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
let dynamicLink = DynamicLinks.dynamicLinks()?.dynamicLink(fromCustomSchemeURL: url)
if let dynamicLink = dynamicLink
{
var path = dynamicLink.url?.path
path?.remove(at: (path?.startIndex)!)
let delimiter = "/"
var fullNameArr = path?.components(separatedBy: delimiter)
let type: String = fullNameArr![0]
let Id: String? = (fullNameArr?.count)! > 1 ? fullNameArr?[1] : nil
if(type == "games")
{
self.callGameDetailView(gameId: Id! , gameType: "created", notificationId: "NIL" )
}else{
var paths = dynamicLink.url?.path
paths?.remove(at: (path?.startIndex)!)
self.setRewardViewController(paths!)
return true
}
}
return FBSDKApplicationDelegate.sharedInstance().application(
application,
open: url,
sourceApplication: sourceApplication,
annotation: annotation)
}
总之,我不知道在应用程序首次运行时或在杀死应用程序后如何处理动态链接?
In short I have no Idea how to handle the dynamic link when app runs first time or run after killing the app?
推荐答案
我也有同样的问题,您需要从launchOptions获取NSUserActivity
I also have same issue, you need to get NSUserActivity from launchOptions
var launchURL :URL? = nil
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
....
// this code should have worked but not working for me with Xcode 9
// if let userActivityDictionary = launchOptions?[.userActivityDictionary] as? [UIApplicationLaunchOptionsKey : Any],
// let auserActivity = userActivityDictionary[.userActivityType] as? NSUserActivity {
// launchURL = auserActivity.webpageURL
// }
if let userActDic = launchOptions?[UIApplicationLaunchOptionsKey.userActivityDictionary] as? [String: Any],
let auserActivity = userActDic["UIApplicationLaunchOptionsUserActivityKey"] as? NSUserActivity{
NSLog("type \(userActDic.self),\(userActDic)") // using NSLog for logging as print did not log to my 'Device and Simulator' logs
launchURL = auserActivity.webpageURL
}
...
}
func applicationDidBecomeActive(_ application: UIApplication) {
if let url = self.launchURL {
self.launchURL = nil
DispatchQueue.main.asyncAfter(deadline: .now()+2.0, execute: {
// wait to initalize notifications
if let dynamicLinks = DynamicLinks.dynamicLinks() {
NSLog("handling \(dynamicLinks)")
dynamicLinks.handleUniversalLink(url) { (dynamiclink, error) in
if let link = dynamiclink?.url {
NSLog("proceessing \(dynamicLinks)")
let strongMatch = dynamiclink?.matchConfidence == .strong
// process dynamic link here
self.processDynamicLink(withUrl: link, andStrongMatch: strongMatch)
}
}
}
})
}
}
这篇关于Firebase Deeplink在Swift 3中未调用AppDelegate的application:continueUserActivity:restorationHandler函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!