skip to Main Content

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

2

Answers


  1. Chosen as BEST ANSWER

    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
    }
    

  2. import FirebaseDynamicLinks
    
    let url = URL(string:
    "https://joyone.page.link/pXJG7y5kLPgxoTyg6?title=Klub+Innowator%C3%B3w+OPZZ")
    let prefix = "https://joyone.page.link" if url?.pathComponents.count
    == 1 {
        print("The provided URL is already a short link: (url!)") } else {
        DynamicLinkComponents(link: url, domainURIPrefix: prefix)?.shorten { [weak self] url, _, error in
            print(url) // https://joyone.page.link/wZiUKDego5EmFY6VA
            print(error) // nil
        } }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search