3

On iOS 14 using SwiftUI, I'm currently trying to test Dynamic Links in the situation where the user clicks the link and installs the app, then opens it up and receives information from that link. I followed the recommendations in this post (How can I test Firebase Dynamic Links if my app is not in the App Store?) and also implemented all the AppDelegate functions on the Firebase iOS website.

However, nothing gets called when I open the link, install the app, and then open the app for the first time (It just says "Pasted from Safari"). The only thing that works is clicking Dynamic links when the app is already installed (it opens up the app and calls the url listener functions correctly).

This is the code for generating the link:

let dynamicLink = URL(string: "http://www.mydomainishereIjustremovedit.com/?referrer=\(referrerID)")!
        
        //guard let uid = Auth.auth().currentUser?.uid else { return }
        if let referralLink = DynamicLinkComponents(link: dynamicLink, domainURIPrefix: "https://penciltestapp.page.link") {
            referralLink.iOSParameters = DynamicLinkIOSParameters(bundleID: "com.penciltestapp.penciltestapp")
            //referralLink.iOSParameters?.minimumAppVersion = "1.0"
            referralLink.iOSParameters?.appStoreID = "962194608" // Opens up a random app on the app store. Just click this to open the app store, and then install your app from XCode
            
            referralLink.shorten { (shortURL, warnings, error) in
                if let error = error {
                    print(error.localizedDescription)
                    return
                }
                self.inviteURL = shortURL
            }
        }
  • Can you add the code that makes the dynamic link in your app? It sounds like you haven't set a fallback URL (ie. if the App is not installed on the device, you need to specify what to open instead (usually a link to the App Store or your website). – nicksarno Nov 10 '20 at 01:06
  • Thanks for your response, Nick. I've added the code. The link is making the app store open correctly - it's just that when I install the app and open it up, it says "Pasted from Safari" but it does not call the url listener methods. I've implemented the override methods in AppDelegate, which are correctly called when the app is already installed, but not when the app *gets* installed and then opened for the first time – Yellow Pencil Nov 10 '20 at 02:46
  • "... The link is making the app store open correctly - it's just that when I install the app and open it up..." If your app is not in the App Store, how are you downloading and installing the build? – nicksarno Nov 10 '20 at 03:00
  • I followed the advice in (https://stackoverflow.com/questions/39605657/how-can-i-test-firebase-dynamic-links-if-my-app-is-not-in-the-app-store) which provides a workaround for this: click the link, (which opens the App Store), and then *freshly* install the app onto your iPhone via XCode. When I do this, a "Pasted from Safari" alert pops up on my screen, but no AppDelegate url listener function gets called – Yellow Pencil Nov 10 '20 at 03:10
  • @YellowPencil did you ever resolve this issue? I am having this issue now exactly as you described above. I am very failure with the whole differed deeplinking system after successfully using it in production in multiple apps built with UIKit, but in SwiftUI I don't get any callback on first app open as you described. – Seamus Oct 21 '22 at 18:43
  • I have also used the pasteboard to read the incoming url, as you said the "Pasted from Safari" shows that the url has been copied from the Pasteboard by the redirect page, however as of iOS16 the user is asked to give permission to read from the past board which they can deny which breaks this approach. – Seamus Oct 21 '22 at 18:46

1 Answers1

1

Dont' forget to implement also this, this was missing in my case

func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any]) -> Bool {
  return application(app, open: url,
                     sourceApplication: options[UIApplication.OpenURLOptionsKey.sourceApplication] as? String,
                     annotation: "")
}
iamin
  • 66
  • 4
  • I have added this code as well, but when we click on dynamic link, `open URL` function was not getting called. Is there any other function will called or what would be the possible issue. Can you please help me? – Harsha Jan 19 '23 at 07:23