5

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

enter image description here

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

Ali M Irshad
  • 116
  • 1
  • 8
  • Did you end up figuring this out? I have a similar issue (4 apps). It seems it may take a while for changes to the apple-app-site-association file to propagate. This may explain why nothing changes when I change the file... – MadMac May 09 '22 at 02:24
  • @MadMac I had added the following to the rewrite rules in firebase.json "rewrites": [ { "source": "/partner/**", "dynamicLinks": true }, { "source": "/customer/**", "dynamicLinks": true }, { "source": "/brand/**", "dynamicLinks": true } ], – Ali M Irshad May 10 '22 at 05:26

2 Answers2

5

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. i.e. 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!

JohnnyD
  • 180
  • 10
  • How do I do this -> "actionCodeSettings.dynamicLinkDomain needs to point to the root and not your configured dynamic link prefix directory". Do I have to do anything to achieve this? – coolcool1994 Dec 23 '20 at 04:54
  • @JohnnyD, I faced similar issue because I own a custom domain. Can you provide more details on "dynamiclinkssubdomain.yourdomain.com"? For example, if the domain is abc.com, you are creating link.abc.com in Firebase? Also as asked above, can you explain more about "actionCodeSettings.dynamicLinkDomain needs to point to the root and not your configured dynamic link prefix directory"? – Calvin Dec 31 '20 at 19:47
  • 36 hours?! How can we test changing the configuration with that delay? – MadMac May 09 '22 at 02:22
  • That's what I've been struggling with for 2 days. I couldn't manage to point "actionCodeSettings.dynamicLinkDomain" to the prefix. Seems that I will have to change my whole structure. For those who didn't understand this: Let's say you want to point dynamic links to: example.com/dynamicLinks But you will be able to point email links to only: example.com/ – MMYurt Feb 28 '23 at 11:14
-1

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.

Eric Gopak
  • 1,663
  • 1
  • 13
  • 26