Я выполнил все шаги из документации по динамическим ссылкам Firebase .
Ассоциированные домены активны, и домен уже добавлен, также я добавляю схемы URL на вкладке информации и программно на вкладке *Функция 1005 *.
Глубокая ссылка открывает приложение, но единственный метод, запускаемый после нажатия на динамическую ссылку, - willContinueUserActivityWithType
, который возвращает ноль 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))")
}
}