Steve Robinson
Steve Robinson

Reputation: 3939

Facebook AppLinkData fetchDeferredApplinkData ReactNative

I'm trying to use the AppLinkData.fetchDeferredAppLinkData SDK method in a React Native app. The official React Native wrapper for FBSDK - https://github.com/facebook/react-native-fbsdk - does not seem to have a binding for the same.

How can I call this method from a React Native application? Just making a call from MainApplication.java / AppDelegate.m should be sufficient?

I'm trying to solve this particular issue with the FB Ads setup:

enter image description here

Upvotes: 3

Views: 950

Answers (1)

skantus
skantus

Reputation: 1043

Following should works for iOS if you already have installed react-native-fbsdk, then in your AppDelegate.m add the next code:

  if (launchOptions[UIApplicationLaunchOptionsURLKey] == nil) {
    // Get user consent
    [FBSDKSettings setAutoInitEnabled:YES];
    [FBSDKApplicationDelegate initializeSDK:nil];
    [FBSDKAppLinkUtility fetchDeferredAppLink:^(NSURL *url, NSError *error) {
      if (error) {
        NSLog(@"Received error while fetching deferred app link %@", error);
      }
      if (url) {
        [[UIApplication sharedApplication] openURL:url];
      }
    }];
  }

For Android you should be like this, in MainActivity:

 protected void onCreate(Bundle savedInstanceState) {
    ...
    
        AppLinkData.fetchDeferredAppLinkData(this, getString(R.string.facebook_app_id),
            new AppLinkData.CompletionHandler() {
                @Override
                public void onDeferredAppLinkDataFetched(AppLinkData appLinkData) {
                    Log.d("SplashActivity", "appLinkData: " + appLinkData);
                }
            }
        );

        Intent intent = getIntent();
        String action = intent.getAction();
        Uri data = intent.getData();
        Log.d("SplashActivity", "data: " + data);

Upvotes: 2

Related Questions