简体   繁体   中英

Can't get iOS app linking to work with firebase dynamic short links

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 fluttertutorial 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!

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 .

Hope this helps!

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM