简体   繁体   中英

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. 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. 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

{
    "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"

    //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

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. Instead I wanted to use 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. If you want to host pages on this domain, you'll want to use the firebase hosting. 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.

It maybe better to create a subdomain to direct to Firebase, that way you can use your own hosting for your main domain. ie yourdomain.com -> Directed to your Server Host dynamiclinkssubdomain.yourdomain.com -> Directed to Firebase

Make sure you've correctly setup the correct AppID, BundleID, StoreID and TeamID under the project settings.

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. Turns out it took about 36 hours. 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.

Hope this helps someone. Spent about 4 days figuring out dynamic links!

Consider trying these two fixes:

  1. The apple-app-site-association file should be under .well-known directory (note the dot).
  2. Remove index.html file from your hosting. This file may interfere with custom domain validation

Edit : you can re-add the index.html file after the domain validation has succeeded.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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