0

I'm working on a Flutter app which displays content from a firebase database and uses firebase dynamic links and deep linking to let users share the content. I'm using short dynamic links, as they are more user friendly, and I followed the official flutter tutorial and example to implement the deep linking. The only difference is taht on iOS I'm using deep linking and app linking (in order to be able to use https url).

Now, in order to explain my problem, imagine I have an object with id 123456 which is showed on a page called page1. I generate a short dynamic using the followinf code (the only thing which differs are the domains):


await FirebaseDynamicLinks.instance.buildShortLink(
        DynamicLinkParameters(
          link: Uri.parse('https://mydomain.app/page1/123456'),
          uriPrefix: 'https://test.mydomain.app/post',
          googleAnalyticsParameters: GoogleAnalyticsParameters(
            campaign: 'test_share',
            content: 123456
          ),
          androidParameters: AndroidParameters(
            packageName: 'es.mydomain.app',
            fallbackUrl: Uri.parse('https://mydomain.app/get/')
          ),
          iosParameters: IOSParameters(
              bundleId: 'es.mydomain.app',
              fallbackUrl: Uri.parse('https://mydomain.app/get/')
          )
        )
    );

Now, a link like https://test.mydomain.app/page1/ADS is created, which doesn't contain the entire id. Here, the main problem is that, on Android everuthing works perfectly, as the link is resolved on the device's default browser and then the app is opened and page1 is opened with the right object id. However, on iOs the app is opened and the received route is /page1/ABC, so although page1 is opened, the received id is not the right one, and the object can't be displayed. On Android, where it's working, the deep linking is specified on the manifest like:

<meta-data android:name="flutter_deeplinking_enabled" android:value="true" />
<intent-filter android:autoVerify="true">
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.BROWSABLE" />
    <data android:scheme="http" android:host="test.mydomain.app" />
    <data android:scheme="https" />
</intent-filter>

On iOS, the app linking is implemented by adding the following code to Info.plist

<key>FlutterDeepLinkingEnabled</key>
<true/>
<key>CFBundleURLTypes</key>
<array>
    <dict>
    <key>CFBundleTypeRole</key>
    <string>Editor</string>
    <key>CFBundleURLName</key>
    <string>test.mydomain.app</string>
    <key>CFBundleURLSchemes</key>
    <array>
    <string>https</string>
    </array>
    </dict>
</array>

And by creating a new entitlement (using xcode) which resulted on the file Runner.entitlements

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>com.apple.developer.associated-domains</key>
    <array>
        <string>applinks:tes.mydomain.app</string>
    </array>
</dict>
</plist>

I've tried checking FirebaseDynamicLinks.instance.getInitialLink() when the navigator is called, but it's always null.

As far as I know, this should be working, but it's obviously not. Does somebody know what could be happening? Any help is welcomed. Thanks a lot!

Javierd98
  • 708
  • 9
  • 27
  • This problem is old and has an [issue in flutter fire](https://github.com/firebase/flutterfire/issues/6913), there are two solutions described in the issue, the simplest is to add an await delay before calling `getInitiaLink` according to `ComplexCarbos`, so you will be able to receive the link. – Chance Oct 16 '22 at 17:35
  • It doesn't matter how long I wait before calling getInitialLink, the returned value is always null. Where should it be called? – Javierd98 Oct 17 '22 at 06:33
  • Are you starting the project in release mode? It's the only way to receive the link on iOS. – Chance Oct 17 '22 at 12:09
  • Yes, I'm using the release mode, but it's still not working. The problem though is not that the link is not opened on the app, but that the received link contains a shortened id, which is not usable. Is this supposed to be fixed by calling getInitialLink? – Javierd98 Oct 17 '22 at 17:22
  • Sorry, I thought your problem was just to recover the link, but if the link was malformed, getinitialink will recover it malformed in the same way. – Chance Oct 18 '22 at 00:16

2 Answers2

0

The example dynamic link seems like a custom domain. If you are using custom domain as a dynamic link prefix, some additional configs needed.

Check this link.

CopsOnRoad
  • 237,138
  • 77
  • 654
  • 440
BHARATH T
  • 501
  • 2
  • 5
  • Hi! Thanks for your response. However, although I've tried adding FirebaseDynamicLinksCustomDomains to Info.plist, the problem remain the same on iOS. The route used to open the app includes the shortened id, so the object can't be displayed – Javierd98 Oct 17 '22 at 06:32
0

I had a similar problem: I was using both deep links and universal links. On Android everything was working as expected but on iOS performing FirebaseDynamicLinks.instance.getInitialLink() after a new install was always null.

In order to make deep links work properly, I had to override a method on the AppDelegate, and that one was interfering with dynamic links. Look upon override func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) There I had to init the FirebaseDynamicLink. Something like that:

    func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
    if let dynamicLink = DynamicLinks.dynamicLinks().dynamicLink(fromCustomSchemeURL: url) {
      // Handle the deep link. 
      return true
    }
    return false
}

Do not forget also to import FirebaseDynamicLinks in the AppDelegate.

I follow the Firebase Receive Dynamic Links on iOS official guide: here