Blog

Firebase Dynamic Links with Scene Delegate

In general, Firebase by Google handles deep and Dynamic Links very well for iOS. But iOS 13 comes with many changes (Scene Delegate!) that aren’t yet fully explained. This is why I made this tutorial. What’s the fuss about deep links in iOS 13? Let's check it out!

What are Firebase Dynamic Links?

If you’re reading this post, you probably know what Dynamic Links are. To make double sure that it is so, deep links and Dynamic Links are urls that link to your app.

    They can:
  • open an app,
  • pass some data to it,
  • check if a user has the particular app installed or not,
  • or open AppStore (or Google Play for Android) with the download path.

Learn more on Firebase Dynamic Links from the video below:

Firebase Dynamic Links in a nutshell

My use case for Dynamic Links in iOS 13

I needed to use all the options shown above. First - I wanted the link to "know" if a user has the app installed on their iPhone. If yes - open it and pass some data. If no - it should have opened AppStore with the download path. Simple?

Well, with Firebase it is kind of simple. However, it is the case only for older iOS versions. Problems started when I passed the tutorial and added all needed lists and functions. Dynamic links started to work well, but with one problem - after opening the app, no data showed up. Soon I found out that the problem was with iOS 13 and Scene Delegate.

App Delegate and Scene Delegate

In older iOS versions, all you needed was to implement 3 functions in App Delegate. But if your project is built with Xcode 11 and targets iOS 13 - which means it comes with Scene Delegate - there are a few steps more.

Besides adding functions mentioned in Google’s tutorial, you need to go to Scene Delegate and add:

func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool

and:

func scene(_ scene: UIScene, continue userActivity: NSUserActivity)

In both functions, we need to implement handler for receiving dynamic links. I recommend creating a separate class for that. This will help us organize the whole structure. In iOS 13 and its newer iterations we’ll be receiving Dynamic Links via Scene Delegate while on older devices this will be done through AppDelegate. It can be a little messy if we don’t take care of proper events handling.

This is not the end yet. After implementing mentioned functions in Scene Delegate, our app should be ready for receiving Dynamic Links from Firebase. But not when it is closed. We also need to take care of this state of the app. Fortunately, this can be easily solved thanks to this generic function:

func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions)

From connectionOptions we need to get the activity.webpageURL object and pass it to:

DynamicLinks.dynamicLinks().handleUniversalLink(url)

This will work when the app is shut down, but we still want to pass the data through a Dynamic Link.

I hope this little tutorial will help you with Firebase Dynamic Links in iOS 13. Good luck!

Related reads:

Check our latest product - it's based on our experience of managing over 50-people strong company. The tool we're missing as a small company and not an enterprise.

humadroid.io is an employee and performance management software. It's an unique tool allowing everyone to be in the loop - by having up to date info about co-workers, time-off, benefits, assets, helping with one-on-ones, being a go-to place for company-wide announcements.

Check out humadroid.io
Top

Contact us

* Required fields

The controller of your personal data provided via this contact form is Prograils sp. z o.o., with a registered seat at Sczanieckiej 9A/10, 60-215 Poznań. Your personal data will be processed in order to respond to your inquiries and for our marketing purposes (e.g. when you ask us for our post-development, maintenance or ad hoc engagements for your app). You have the rights to: access your personal data, rectify or erase your personal data, restrict the processing of your personal data, data portability and to object to the processing of your personal data. Learn more.

Notice

We do not track you online. We use only session cookies and anonymous identifiers for the purposes specified in the cookie policy. No third-party trackers.

I understand
Elo Mordo!Elo Mordo!