Marco Brugali
Marco Brugali

Reputation: 125

Firebase Dynamic Link on getInitialLink is null only on IOS and production link (React Native)

Is a React Native app and i use @react-native-firebase/dynamic-links version 7.1.0 (rnFirebase). On android my dynamic link work correctly. On ios with firebase test link work correctly (myUrl.page.link), but with a verified prefix url (myUrl) app are opened but my function dynamicLinks().getInitialLink() return null. (I have add correctly url on associated domains in xcode)

I created the link with

    const link = await dynamicLinks().buildShortLink(
  {
    link: encodeURI(
      `myUrl/${list.generatedString}`
    ),
    domainUriPrefix: 'myUrl',
    analytics: {
      campaign: 'banner'
    },
    navigation: {
      forcedRedirectEnabled: false,
    },
    ios: {
      bundleId: 'com.runeapp.gift-it',
      // customScheme: 'giftit',
      appStoreId: '1503678456'
    },
    android: {
      packageName: 'com.runeapp.giftit'
    }
  },
  'SHORT'
);

I wonder if the problem can be derived from the fact that the app has not yet been published on the app store.

Anyone have any idea? thanks

Upvotes: 2

Views: 6669

Answers (4)

ABHILASH BHOSLE
ABHILASH BHOSLE

Reputation: 1

#import <RNFBDynamicLinksAppDelegateInterceptor.h>  // add this line
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  [RNFBDynamicLinksAppDelegateInterceptor sharedInstance]; // add this line
 //-------
 // other code
 //------- 
}
>

Upvotes: 0

Adrian Buciuman
Adrian Buciuman

Reputation: 325

My issue was because I'm using API key restriction for the API key I use in my application. I extended the restriction to allow usage with the Firebase Dynamic Links API.

To allow your API key in question to be used with the new Firebase Dynamic Links API:

  • go to the Google Cloud Console
  • choose the relevant project (i.e. the project you use for your application) open the menu and go to APIs & Services -> Credentials
  • click Edit API key for the API key in question
  • scroll down to API restrictions section
  • from the dropdown, choose Firebase Dynamic Links API
  • click Save

wait a couple of minutes for Google servers to update and retry...

Upvotes: 2

Luthfulahi
Luthfulahi

Reputation: 133

dynamicLinks().getInitialLink() doesn't seem to work on iOS but here is a simple workaround I used in solving that:

When a user is on an iOS device, use the Linking package in react-native, then use the dynamicLinks().resolveLink() passing the URL returned from Linking. getInitialURL(), which would return the same response as dynamicLinks().getInitialLink(). Here is a snippet:

if (Platform.OS === 'ios') {
 Linking.getInitialURL()
  .then(res => {
    dynamicLinks().resolveLink(res).then(response => {
      console.log(response.url);
    })
 })
}

You could use the value from the Linking library directly but it is helpful to call the dynamic link resolveLink() in case you added extra parameters while building your link.

Upvotes: 10

Rasmus Christensen
Rasmus Christensen

Reputation: 8541

When you open the app from the background you need to call onLink instead of getInitialLink

Upvotes: 1

Related Questions