Search code examples
iosswiftfirebase-dynamic-links

How to check if Firebase DynamicLink is already shortened and there is no need to shorten it again?


This is my simple function:

import FirebaseDynamicLinks
   
let url = URL(string: "https://joyone.page.link/pXJG7y5kLPgxoTyg6?title=Klub+Innowator%C3%B3w+OPZZ")
let prefix = "https://joyone.page.link"
DynamicLinkComponents(link: url, domainURIPrefix: prefix)?.shorten { [weak self] url, _, error in
    print(url) // https://joyone.page.link/wZiUKDego5EmFY6VA
    print(error) // nil
}

This function should return error Cannot shorten a short Dynamic Link but it does not. It works on library for Android... but not on ios.

on Android library there is an error returned:

Cannot shorten a short Dynamic Link: https://joyone.page.link/pXJG7y5kLPgxoTyg6?title=Klub+Innowator%C3%B3w+OPZZ

Solution

  • There is another method for this:

    DynamicLinkComponents.shortenURL(url, options: nil) { [weak self] url, _, error in
        // here you receive a specific error if link is already shortened
    }