Firebase Deeplink 不触发应用程序:continueUserActivity:restorationHandler,Swift 4.2 Xcode10。
Posted
技术标签:
【中文标题】Firebase Deeplink 不触发应用程序:continueUserActivity:restorationHandler,Swift 4.2 Xcode10。【英文标题】:Firebase Deeplink not trigger application:continueUserActivity:restorationHandler, Swift 4.2 Xcode10. 【发布时间】:2018-10-18 14:43:35 【问题描述】:我遵循了Firebase Dynamic Links 文档中的所有步骤。
关联域处于活动状态,并且域已添加,我还在信息选项卡中添加 URL 方案,并以编程方式在 launchOptions
函数中添加。
深层链接正在打开应用,但点击动态链接后触发的唯一方法是willContinueUserActivityWithType
,它返回 nil userActivity
在提到continueUserActivity
的文档中,如果应用程序在后台运行,则必须触发,但在我的情况下没有发生,我可以找到任何其他方法来获取深度链接数据。
这是我的 AppDelegate 代码:
import UIKit
import Firebase
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool
let options = FirebaseOptions(contentsOfFile: filePath)
options?.deepLinkURLScheme = "com.example"
FirebaseApp.configure(options: options!)
.
.
.
func applicationWillResignActive(_ application: UIApplication)
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
func applicationDidEnterBackground(_ application: UIApplication)
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
func applicationWillEnterForeground(_ application: UIApplication)
// Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
func applicationDidBecomeActive(_ application: UIApplication)
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
print("applicationDidBecomeActive")
func applicationWillTerminate(_ application: UIApplication)
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
func application(_ application: UIApplication, willContinueUserActivityWithType userActivityType: String) -> Bool
if let incomigURL = userActivity?.webpageURL
let linkHandle = DynamicLinks.dynamicLinks().handleUniversalLink(incomigURL) (dynamiclink, error) in
if let dynamiclink = dynamiclink, let _ = dynamiclink.url
self.handleIncomingDynamicLink(dynamicLink: dynamiclink)
else
print("willContinueUserActivityWithType | dynamiclink = nil")
return linkHandle
print("willContinueUserActivityWithType | userActivity = nil")
return false
func application(application: UIApplication, continueUserActivity userActivity: NSUserActivity, restorationHandler: ([AnyObject]?) -> Void) -> Bool
if let incomigURL = userActivity.webpageURL
let linkHandle = DynamicLinks.dynamicLinks().handleUniversalLink(incomigURL) (dynamiclink, error) in
if let dynamiclink = dynamiclink, let _ = dynamiclink.url
self.handleIncomingDynamicLink(dynamicLink: dynamiclink)
else
print("continueUserActivity | dynamiclink = nil")
return linkHandle
print("continueUserActivity = nil")
return false
@available(ios 9.0, *)
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any]) -> Bool
return application(app, open: url,
sourceApplication: options[UIApplication.OpenURLOptionsKey.sourceApplication] as? String,
annotation: "")
func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool
print("Handle deep link.")
return true
func handleIncomingDynamicLink(dynamicLink: DynamicLink)
print("Your dynamic link parameter is = \(String(describing: dynamicLink.url))")
【问题讨论】:
【参考方案1】:在 swift 4.2 中将 Instant 方法更改为:
func application(_ application: UIApplication,
continue userActivity: NSUserActivity,
restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool
所以为了处理 Firebase 深层链接 NSUserActivity
函数必须是这样的:
func application(_ application: UIApplication,
continue userActivity: NSUserActivity,
restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool
if let incomigURL = userActivity.webpageURL
let linkHandle = DynamicLinks.dynamicLinks().handleUniversalLink(incomigURL) (dynamiclink, error) in
if let dynamiclink = dynamiclink, let _ = dynamiclink.url
self.handleIncomingDynamicLink(dynamicLink: dynamiclink)
else
print("dynamiclink = nil")
return linkHandle
print("userActivity = nil")
return false
特别感谢user1376400
【讨论】:
【参考方案2】:您使用的团队 ID 配置文件是否与您在应用关联文件中提到的相同 "appID":"TeamID","paths":["/*"]] 在您的应用程序中。
检查您的域名是否与 Associated Domains applink 匹配。
使用验证器 https://branch.io/resources/aasa-validator/ 验证您的 apple-app-site-association
【讨论】:
是的,我刚刚检查了域是否有效,并且团队 ID 与我用于应用程序调试模式的团队 ID 相同,不得不提的是,我还在 Firebase 控制台中添加了相同的团队 ID。这就是我的路径的样子: "appID":"TeamID.bundleID","paths":["/*"]] 不要在 Firebase 控制台中使用团队 ID。从您用于运行应用程序的个人资料中找到您的团队 ID。 developer.apple.com/account/#/membership 。尝试长按链接。它是否显示打开的应用程序。一旦你在网络中打开它总是在网络中打开它自己 是的,我从这里获取 ID 并在 Firebase 控制台中设置它。 你能分享你的网址吗?我可以在这里查看 检查此方法在 Swift 4.2 developer.apple.com/documentation/uikit/uiapplicationdelegate/… 中已更改。我认为您是从示例中复制的。写一个新鲜的方法并保持简单以上是关于Firebase Deeplink 不触发应用程序:continueUserActivity:restorationHandler,Swift 4.2 Xcode10。的主要内容,如果未能解决你的问题,请参考以下文章
如何在 Deeplink 消息中添加自定义文本而不是 URL
Deeplink url 需要播放商店/应用商店,但如果安装则不打开应用
Firebase onauthstatechanged 在页面加载时触发不一致
Cloud Functions for Firebase 错误:“400,不允许更改函数触发器类型或事件提供程序”