3

I am trying to integrate facebook app links for my react-native app and unfortunately it doesn't seem to work as expected. First of all, I followed the instructions mentioned in the docs. So I used react-native-facebook-app-link and tried to verify it using the ads helper and I am unable to get the url.

This is the code I have added,

<activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:launchMode="singleTask"
        android:screenOrientation="portrait"
        android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode"
        android:windowSoftInputMode="adjustPan"
        android:exported="true">

          <intent-filter>
              <data android:scheme="sample" android:host="open"/>
              <action android:name="android.intent.action.VIEW"/>
              <category android:name="android.intent.category.DEFAULT"/>
              <category android:name="android.intent.category.BROWSABLE"/>
          </intent-filter>

      </activity>

and I have added the key in the manifest file,

<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/facebook_app_id"/>

<meta-data android:name="com.facebook.sdk.AdvertiserIDCollectionEnabled"
        android:value="true"/>

and also I have implemented the method,

@Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
      AppLinkData.fetchDeferredAppLinkData(this,
          new AppLinkData.CompletionHandler() {
              @Override
              public void onDeferredAppLinkDataFetched(AppLinkData appLinkData) {
                    Log.d("urls", String.valueOf(appLinkData));
              }
          }
      );
  }

Since, I am building the app using react native, in the app.js i have added the below code,

async componentDidMount () {
        FacebookAppLink.initializeSDK();
        const url = await FacebookAppLink.fetchUrl();
        if(url){
           console.log("FACEBOOOK URL: ", url)
        }
}

Finally, I tried using the ads helper, enter image description here

However I am not receiving the URL. It gets redirected to the app but the url isn't printed in the console. And please note the steps I followed are,

  1. Uninstalled the app
  2. Generated the link and I got the notification in facebook
  3. Rebuild and install the app using android studio
  4. Then click on that link

I am not sure what I have done wrong. Some help will be greatly appreciated. Thanks in advance.

someone
  • 6,577
  • 7
  • 37
  • 60
SHA
  • 81
  • 6

1 Answers1

1

I think you do not need to implement following native method again with your project

@Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
      AppLinkData.fetchDeferredAppLinkData(this,
          new AppLinkData.CompletionHandler() {
              @Override
              public void onDeferredAppLinkDataFetched(AppLinkData appLinkData) {
                    Log.d("urls", String.valueOf(appLinkData));
              }
          }
      );
  }

It is already implemented in that library and from there it resolves/reject promise.

You just need to write what you have written in componentDidMount and it should work.

Ravi
  • 34,851
  • 21
  • 122
  • 183