iOS/Swift:如何通过在控制台Firebase上配置一个链接来获得来自App Store的安装的动态深链接?

发布于 2025-02-13 23:21:05 字数 5926 浏览 0 评论 0原文

当不安装应用程序并打开Dynamic链接时,App Store会很好地打开,但是一旦安装,如果我单击“打开”,它将打开应用程序,它将显示一条消息“导航器中的链接粘贴” ,但是动态链接仅在没有参数的情况下启动

func应用程序(_应用程序:UIAPPLICATION,继续用户行动: nsuseractivity,RestorationHandler:@escaping ([uiuseractivityRestoring]?) - > void) - > bool {

这是函数:

     func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
          let handled = DynamicLinks.dynamicLinks()
            .handleUniversalLink(userActivity.webpageURL!) { dynamiclink, error in
              // ...
                print(dynamiclink!)
                
                let urlStr: String = (dynamiclink?.url?.absoluteString.lowercased())!
                //  UserDefaults.standard.set(urlStr, forKey: "url")
                
                if (urlStr.contains("test?code=azerty")) {
                    UserDefaults.standard.set(urlStr, forKey: "url")
                    
                    let str: String = UserDefaults.standard.value(forKey: "url") as! String
                    if (str.contains("test?code=azerty"))
                       {
                        let alert = UIAlertController(title: "test", message: str, preferredStyle: .alert)
                        
                        alert.addAction(UIAlertAction(title: "OK", style:  .default, handler: { action in
                            switch action.style{
                            case .default:
                                print("default")
                                
                            case .cancel:
                                print("cancel")
                                
                            case .destructive:
                                print("destructive")
                                
                            }}))
                        
                        let navigationController = application.windows[0].rootViewController as! UINavigationController
                        let activeViewCont = navigationController.visibleViewController
                        activeViewCont?.view.isUserInteractionEnabled = false
                        //activeViewCont!.present(alertController, animated: true, completion: nil)
                        DispatchQueue.main.asyncAfter(deadline: .now() + 5.0, execute: {
                            activeViewCont!.present(alert, animated: true, completion: nil)
                        })
                       
                       }
                }
                
            }
    
          return handled
        }
 func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
        print(url)
        print("handleOpenURL")
        
        //let urlStr: String = url.absoluteString.replacingOccurrences(of: "colas://", with: "")
        let urlStr: String = url.absoluteString.lowercased()
        //  UserDefaults.standard.set(urlStr, forKey: "url")
        
        if (urlStr.contains("test?code=azerty")) {
            UserDefaults.standard.set(urlStr, forKey: "url")
            
            let str: String = UserDefaults.standard.value(forKey: "url") as! String
            if (str.contains("test?code=azerty"))
               {
                let alert = UIAlertController(title: "test", message: str, preferredStyle: .alert)
                
                alert.addAction(UIAlertAction(title: "OK", style:  .default, handler: { action in
                    switch action.style{
                    case .default:
                        print("default")
                        
                    case .cancel:
                        print("cancel")
                        
                    case .destructive:
                        print("destructive")
                        
                    }}))
                
                let navigationController = app.windows[0].rootViewController as! UINavigationController
                let activeViewCont = navigationController.visibleViewController
                activeViewCont?.view.isUserInteractionEnabled = false
                //activeViewCont!.present(alertController, animated: true, completion: nil)
                DispatchQueue.main.asyncAfter(deadline: .now() + 5.0, execute: {
                activeViewCont!.present(alert, animated: true, completion: nil)
                })
               }
        }


        return true
    }

info plist:

<key>FirebaseDynamicLinksCustomDomains</key>
    <array>
        <string>https://myapp.page.link</string>
    </array>

app中的域:

网站上的域:

firebase选项:

方案:

使用Dynamic链接在App Store安装应用程序之后,我该如何触发函数包含参数?

信息:

xxxx.xxxxxxxxx.myapp://google/link/?deep_link_id=https://myapp.page.link/&match_type=unique&utm_medium=dynamic_link&request_ip_version=IP_V4&utm_source=firebase&match_message=Link is uniquely matched for this device.

When the app is not installed, and the user open the dynamic link, the app store is well opened, but once installed, if I click on "open", it open the apps, it says a message "link paste from the navigator", but the dynamic link is only launched without the parameters

func application(_ application: UIApplication, continue userActivity:
NSUserActivity, restorationHandler: @escaping
([UIUserActivityRestoring]?) -> Void) -> Bool {

Here is the function:

     func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
          let handled = DynamicLinks.dynamicLinks()
            .handleUniversalLink(userActivity.webpageURL!) { dynamiclink, error in
              // ...
                print(dynamiclink!)
                
                let urlStr: String = (dynamiclink?.url?.absoluteString.lowercased())!
                //  UserDefaults.standard.set(urlStr, forKey: "url")
                
                if (urlStr.contains("test?code=azerty")) {
                    UserDefaults.standard.set(urlStr, forKey: "url")
                    
                    let str: String = UserDefaults.standard.value(forKey: "url") as! String
                    if (str.contains("test?code=azerty"))
                       {
                        let alert = UIAlertController(title: "test", message: str, preferredStyle: .alert)
                        
                        alert.addAction(UIAlertAction(title: "OK", style:  .default, handler: { action in
                            switch action.style{
                            case .default:
                                print("default")
                                
                            case .cancel:
                                print("cancel")
                                
                            case .destructive:
                                print("destructive")
                                
                            }}))
                        
                        let navigationController = application.windows[0].rootViewController as! UINavigationController
                        let activeViewCont = navigationController.visibleViewController
                        activeViewCont?.view.isUserInteractionEnabled = false
                        //activeViewCont!.present(alertController, animated: true, completion: nil)
                        DispatchQueue.main.asyncAfter(deadline: .now() + 5.0, execute: {
                            activeViewCont!.present(alert, animated: true, completion: nil)
                        })
                       
                       }
                }
                
            }
    
          return handled
        }
 func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
        print(url)
        print("handleOpenURL")
        
        //let urlStr: String = url.absoluteString.replacingOccurrences(of: "colas://", with: "")
        let urlStr: String = url.absoluteString.lowercased()
        //  UserDefaults.standard.set(urlStr, forKey: "url")
        
        if (urlStr.contains("test?code=azerty")) {
            UserDefaults.standard.set(urlStr, forKey: "url")
            
            let str: String = UserDefaults.standard.value(forKey: "url") as! String
            if (str.contains("test?code=azerty"))
               {
                let alert = UIAlertController(title: "test", message: str, preferredStyle: .alert)
                
                alert.addAction(UIAlertAction(title: "OK", style:  .default, handler: { action in
                    switch action.style{
                    case .default:
                        print("default")
                        
                    case .cancel:
                        print("cancel")
                        
                    case .destructive:
                        print("destructive")
                        
                    }}))
                
                let navigationController = app.windows[0].rootViewController as! UINavigationController
                let activeViewCont = navigationController.visibleViewController
                activeViewCont?.view.isUserInteractionEnabled = false
                //activeViewCont!.present(alertController, animated: true, completion: nil)
                DispatchQueue.main.asyncAfter(deadline: .now() + 5.0, execute: {
                activeViewCont!.present(alert, animated: true, completion: nil)
                })
               }
        }


        return true
    }

Info plist:

<key>FirebaseDynamicLinksCustomDomains</key>
    <array>
        <string>https://myapp.page.link</string>
    </array>

Domains in app:
domainsInApp

Domains on website:
domainsOnSite

FireBase option:

enter image description here
enter image description here

Scheme:
enter image description here

How can I get the function fired, just after install the application from the app store, with the dynamic link containing the parameters?

Message:

xxxx.xxxxxxxxx.myapp://google/link/?deep_link_id=https://myapp.page.link/&match_type=unique&utm_medium=dynamic_link&request_ip_version=IP_V4&utm_source=firebase&match_message=Link is uniquely matched for this device.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

百合的盛世恋 2025-02-20 23:21:06

两个问题是:
1/动态&nbsp; url的良好写作:&nbsp;

https://yourapp.page.link/?link=https://yourapp.com/test=12345&isi=14602xxxxx&ibi=com.xxxx.yourapp

这是创建Info.plist中XCode中的url

2/参数的好方法很重要:&nbsp;

<key>FirebaseDynamicLinksCustomDomains</key>
    <array>
        <string>https://yourapp.com/link</string>
    </array>

the two problems were :
1/ the good writing of the dynamical url : 

https://yourapp.page.link/?link=https://yourapp.com/test=12345&isi=14602xxxxx&ibi=com.xxxx.yourapp

This is the good way to create the url

2/ The parameter in info.plist in Xcode is important : 

<key>FirebaseDynamicLinksCustomDomains</key>
    <array>
        <string>https://yourapp.com/link</string>
    </array>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文