简体   繁体   English

具有自定义域的 Firebase 动态链接

[英]Firebase dynamic links with custom domain

I had integrated Firebase Dynamic links in multiple iOS apps, which is in the same firebase project and it was working fine.我在多个 iOS 应用程序中集成了 Firebase 动态链接,这些应用程序位于同一个 Firebase 项目中,并且运行良好。 But when I installed both apps on same device, the dynamic links were not opening specific app on the device.但是当我在同一设备上安装两个应用程序时,动态链接没有打开设备上的特定应用程序。 So, I registered a custom subdomain with firebase with a custom apple-app-site-association in the root directory.因此,我在根目录中使用自定义 apple-app-site-association 向 firebase 注册了一个自定义子域。 But still I am having the same issue.但我仍然有同样的问题。 I want to generate short dynamic link like我想生成短动态链接,如

https://apps.mybrand.co.id/partner/xXXx

Files in public folder公用文件夹中的文件

在此处输入图片说明

apple-app-site-association苹果应用程序站点关联

{
        "applinks": {
            "apps": [],
            "details": [
                {
                    "appID": "XXXXX.com.XXXX.Customer",
                    "paths":[ "/customer/", "/brand/"]
                },
                {
                    "appID": "XXXXX.com.XXXX.Partner",
                    "paths": ["/partner/"]
                }
            ]
        }
    }

Firebase.json Firebase.json

{
    "hosting": {
        "public": "public",
        "ignore": [
            "firebase.json",
            "**/.*",
            "**/node_modules/**"
        ],
        "appAssociation": "AUTO",
        "rewrites": [
            {
                "source": "/**",
                "dynamicLinks": true
            }
        ],
        "headers": [
            {
                "source": "apple-app-site-association",
                "headers": [{"key": "Content-Type", "value": "application/json"}]
            }
        ]
    }
}

I am using the following code to generate link我正在使用以下代码生成链接

//custom domain registred on firebase let dynamicLink = "apps.mybrand.co.id" //在firebase上注册的自定义域 let dynamicLink = "apps.mybrand.co.id"

    //create link url components
    var urlComponents = URLComponents()
    urlComponents.scheme = "https"
    urlComponents.host = dynamicLink
    urlComponents.path = "/data"
    let queryItem = URLQueryItem(name: "myBrandReferCode", value: "60C38A")
    urlComponents.queryItems = [queryItem]

    // get the url from url component
    guard let linkParameter = urlComponents.url else {
        return
    }
    //print the url string for debugging
    print("I am sharing \(linkParameter.absoluteString)")

    // create dynamic link components with custom domain
    guard let shareLink = DynamicLinkComponents.init(link: linkParameter, domainURIPrefix: "https://apps.mybrand.co.id/partner") else {
        print("Unable to create FDL component.")
        return
    }

    shareLink.iOSParameters = DynamicLinkIOSParameters(bundleID: "com.ranosys.DFM-BM")
    //temporary app id of another app, same in firebase console app settings
    shareLink.iOSParameters?.appStoreID = "359085099"

    //call shorten method to get short dynamic link
    shareLink.shorten { (shortURL, warnings, error) in

        for warning in warnings ?? [String]() {
            print(warning)
        }

        //remove wait view from the button
        self.shareCodeButton.removeWaitView()
        //if there is any error, print it
        if let error = error {
            print(error.localizedDescription)
            return
        }
        //if dynamic link is successfully shortened
        if let shortLink = shortURL {
            //show the activity controller
            self.showActivityCoontroller(shortLink)
        }
    }

But I am getting error that The operation couldn't be completed. Your project does not own Dynamic Links domain: https://apps.mybrand.co.id但是我收到The operation couldn't be completed. Your project does not own Dynamic Links domain: https://apps.mybrand.co.id错误The operation couldn't be completed. Your project does not own Dynamic Links domain: https://apps.mybrand.co.id The operation couldn't be completed. Your project does not own Dynamic Links domain: https://apps.mybrand.co.id

Not sure if this will help anyone but I had similar issues.不确定这是否会帮助任何人,但我有类似的问题。 I wanted to setup my own domain to use as a Dynamic Link for passwordless authentication instead of the appname.page.link Dynamic Link domain you can use by default.我想设置我自己的域以用作无密码身份验证的动态链接,而不是默认情况下可以使用的 appname.page.link 动态链接域。 Instead I wanted to use myowndomain.com/DynamicLinks.相反,我想使用 myowndomain.com/DynamicLinks。

To use Dynamic Links with Firebase in this way, you have to give control of the domain to Firebase which will then generate the JSON apple-app-site-association file for you in the root of the domain.要以这种方式将动态链接与 Firebase 结合使用,您必须将域的控制权交给 Firebase,后者将在域的根目录中为您生成 JSON apple-app-site-association 文件。 If you want to host pages on this domain, you'll want to use the firebase hosting.如果您想在此域上托管页面,则需要使用 firebase 托管。 In otherwords, for a domain to use dynamic links with Firebase, the domain must be controlled by Firebase by creating the necessary associated DNS records to point to their servers.换句话说,要使域使用与 Firebase 的动态链接,该域必须由 Firebase 控制,方法是创建必要的关联 DNS 记录以指向其服务器。

It maybe better to create a subdomain to direct to Firebase, that way you can use your own hosting for your main domain.创建一个指向 Firebase 的子域可能更好,这样您就可以将自己的主机用于主域。 ie yourdomain.com -> Directed to your Server Host dynamiclinkssubdomain.yourdomain.com -> Directed to Firebase即 yourdomain.com -> 定向到您的服务器主机 dynamiclinkssubdomain.yourdomain.com -> 定向到 Firebase

Make sure you've correctly setup the correct AppID, BundleID, StoreID and TeamID under the project settings.确保在项目设置下正确设置了正确的 AppID、BundleID、StoreID 和 TeamID。

But here is where I got frustrated: I did everything as expected and it still didn't work.但这就是我感到沮丧的地方:我按预期做了所有事情,但仍然没有奏效。 I contacted Apple support and they said it takes time for the apple-app-site-association to propagate.我联系了 Apple 支持,他们说 apple-app-site-association 需要时间来传播。 Turns out it took about 36 hours.结果证明花了大约36个小时。 Works perfectly now.现在完美运行。 Also discovered that the file is created in the root so your actionCodeSettings.dynamicLinkDomain needs to point to the root and not your configured dynamic link prefix directory.还发现该文件是在根目录中创建的,因此您的 actionCodeSettings.dynamicLinkDomain 需要指向根目录而不是您配置的动态链接前缀目录。

Hope this helps someone.希望这可以帮助某人。 Spent about 4 days figuring out dynamic links!花了大约 4 天的时间找出动态链接!

Consider trying these two fixes:考虑尝试以下两个修复程序:

  1. The apple-app-site-association file should be under .well-known directory (note the dot). apple-app-site-association文件应该在.well-known目录下(注意点)。
  2. Remove index.html file from your hosting.从您的主机中删除index.html文件。 This file may interfere with custom domain validation此文件可能会干扰自定义域验证

Edit : you can re-add the index.html file after the domain validation has succeeded.编辑:您可以在域验证成功后重新添加index.html文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM