[英]iOS Application: Firebase Dynamic Links are not working with latest Pod file
We integrated the latest Dynamic link Pod to our iOS application.我们将最新的动态链接 Pod 集成到我们的 iOS 应用程序中。
Whenever we open the link of firebase no function in triggered in our Appdelegate.每当我们打开 firebase 的链接时,我们的 Appdelegate 中都没有触发任何功能。 Check the method we implemented in App delegate检查我们在 App 委托中实现的方法
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
DynamicLinks.dynamicLinks().handleUniversalLink(userActivity.webpageURL!) { (dynamiclink, error) in
if(dynamiclink != nil){
let aStr = dynamiclink!.url!.absoluteString
print("reopen url :\(String(describing: aStr.removingPercentEncoding))")
let decodeUrl = aStr.removingPercentEncoding!
}
}
return true
}
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
print("got link1")
print(" first time url :\(url)")
let aStr = url.absoluteString
print("url :\(String(describing: aStr.removingPercentEncoding))")
let decodeUrl = aStr.removingPercentEncoding!
if let dynamicLink = DynamicLinks.dynamicLinks().dynamicLink(fromCustomSchemeURL: url) {
if dynamicLink.url != nil{
let aStr = dynamicLink.url!.absoluteString
let decodUrl = aStr.removingPercentEncoding!
}
}
return true }
We are using a custom domain in our application, we added them in info.plist too我们在应用程序中使用了自定义域,我们也在 info.plist 中添加了它们
<key>FirebaseDynamicLinksCustomDomains</key>
<array>
<string>https://page.google.com/newrequest</string>
</array>
<key>FirebaseAppDelegateProxyEnabled</key>
<string>YES</string>
We added a dynamic link URL to our AssociatedDomains with a prefix of app links like applinks:page.google.com
我们向 AssociatedDomains 添加了一个动态链接 URL,并带有applinks:page.google.com
等应用链接前缀
In iOS 13, AppDelegate methods will not call.在 iOS 13 中,不会调用 AppDelegate 方法。 Add SceneDelegate to your project.将 SceneDelegate 添加到您的项目中。 Add func scene(_ scene: UIScene, continue userActivity: NSUserActivity) { print(userActivity.webpageURL) }
添加func scene(_ scene: UIScene, continue userActivity: NSUserActivity) { print(userActivity.webpageURL) }
we will get userActivity.webpageURL will be our long dynamic link.我们将得到 userActivity.webpageURL 将是我们的长动态链接。
For those who are still struggling on managing deep links in SceneDelegate, this answer might helpful.对于那些仍在努力管理 SceneDelegate 中的深层链接的人来说,这个答案可能会有所帮助。
Case 1: App is running (foreground & background):案例 1:应用程序正在运行(前台和后台):
First you should keep in mind that after iOS 13 update the deep links are not managed by the UIApplicationDelegate
, this job is hand over to SceneDelegate
.首先,您应该记住,在 iOS 13 更新后,深层链接不再由UIApplicationDelegate
管理,这项工作将移交给SceneDelegate
。
So for the first case you need to add below method to handle the event when user clicks on deep link因此,对于第一种情况,您需要添加以下方法来处理用户单击深层链接时的事件
func scene(_ scene: UIScene, continue userActivity: NSUserActivity) {
guard userActivity.activityType == NSUserActivityTypeBrowsingWeb,
let url = userActivity.webpageURL,
let host = url.host else {
return
}
DynamicLinks.dynamicLinks().handleUniversalLink(url) { dynamicLink, error in
guard error == nil,
let dynamicLink = dynamicLink,
let urlString = dynamicLink.url?.absoluteString else {
return
}
print("Dynamic link host: \(host)")
print("Dyanmic link url: \(urlString)")
// Handle deep links
self.handleDeepLink(urlString: urlString)
print("Dynamic link match type: \(dynamicLink.matchType.rawValue)")
}
}
Case 2: App is not running (Kill mode):情况 2:应用程序未运行(Kill 模式):
If the application is not running the the deep links are available in connectionOptions
of the SceneDelegate
.如果应用程序未运行,则SceneDelegate
connectionOptions
中提供了深层链接。 So you need to write a code to manage Firebase deep links in willConnectTo(:)
method.因此,您需要编写代码来管理willConnectTo(:)
方法中的 Firebase 深层链接。
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
if let userActivity = connectionOptions.userActivities.first {
if let incomingURL = userActivity.webpageURL {
_ = DynamicLinks.dynamicLinks().handleUniversalLink(incomingURL) { (dynamicLink, error) in
guard error == nil else { return }
if let dynamicLink = dynamicLink {
if let urlString = dynamicLink.url?.absoluteString {
// Handle deep links
self.handleDeepLink(urlString: urlString)
}
}
}
}
}
}
Try this: https://stackoverflow.com/a/59765601/2781088 This might solve your initial problem for DL and follow the below code for the problem mentioned in the comments.试试这个: https : //stackoverflow.com/a/59765601/2781088这可能会解决您最初的 DL 问题,并按照以下代码解决评论中提到的问题。
You can get the URL in the following functions (Add these methods into your App Delegate):您可以在以下函数中获取 URL(将这些方法添加到您的 App Delegate):
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
if DynamicLinks.dynamicLinks().shouldHandleDynamicLink(fromCustomSchemeURL: url) {
let dynamicLink = DynamicLinks.dynamicLinks().dynamicLink(fromCustomSchemeURL: url)
self.handleDynamicLink(dynamicLink)
return true
}
}
And和
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
if let incomingURL = userActivity.webpageURL {
print(incomingURL)
let linkHandled = DynamicLinks.dynamicLinks().handleUniversalLink(incomingURL) { (dynamicLink, error) in
guard error == nil else {
print("Found an error! \(error!.localizedDescription)")
return
}
if let dynamicLink = dynamicLink {
self.handleDynamicLink(dynamicLink)
}
}
if linkHandled {
return true
}
else {
//May be do other things with our incoming URL?
return false
}
}
return false
}
handleDynamicLink method: handleDynamicLink 方法:
func handleDynamicLink(_ dynamicLink: DynamicLink?) {
guard let dynamicLink = dynamicLink else { return }
guard let deepLink = dynamicLink.url else { return }
}
Don't forget to add this:不要忘记添加这个:
Hope that will solve your issue.希望能解决你的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.