Hi fellow coders!
Recently we needed to show our react native app ads on different platforms like Facebook or Instagram so for that you must have FB SDK installed and configured in your app.
React Native FBSDK (Not Supported)
I came to know that Facebook dropped the support from the official wrapper library and created Facebook SDKs for Android and iOS instead. But if you are only a JS dev you won't understand the swift code mentioned in their iOS SDK and you'll get confused like me.
React Native FBSDK Next
Also, they gave us the way towards the alternative library react-native-fbsdk-next. So today I want to share how I installed and configured FB SDKs through this library.
This project aims to keep continuity of the React Native FBSDK from Facebook. As Facebook dropped support from it. As a community for this is our effort in order to keep upgrading and improving support for this module.
React Native FBSDK is a wrapper around the iOS Facebook SDK and Android Facebook SDK, allowing for Facebook integration in React Native apps. Access to native components, from login to sharing, is provided entirely through documented JavaScript modules so you don't have to call a single native function directly.
Functionality is provided through one single npm package so you can use it for both platforms without downloading any extra packages. Follow this guide to use react-native-fbsdk in your React Native app. You can also visit https://developers.facebook.com/docs/react-native for tutorials and reference documentation.
Replace 1234 with your Facebook app id and 56789 with client token value from the Facebook developer dashboard.
3) After that open the /app/manifests/AndroidManifest.xml file and add meta-data to the application element.
Now here replace fbAPP-ID and APP-ID with your Facebook id available in the Facebook developer app dashboard. Put your client token in place of CLIENT-TOKEN available in Advanced Settings and the last replace APP-NAME with your app name.
2) Now open your AppDelegate.m file and paste this code there.
#import<FBSDKCoreKit/FBSDKCoreKit.h>// <- Add This Import#import<React/RCTLinkingManager.h>// <- Add This Import-(BOOL)application:(UIApplication*)appopenURL:(NSURL*)urloptions:(NSDictionary<UIApplicationOpenURLOptionsKey,id>*)options{if ([[FBSDKApplicationDelegatesharedInstance]application:appopenURL:urloptions:options]){returnYES;}if ([RCTLinkingManagerapplication:appopenURL:urloptions:options]){returnYES;}returnNO;}
3) Initialise FB SDK in the same file. Go to the didFinishLaunchingWithOptions function and paste this line before return YES; statement
4) Now in the last as I wanted our app for Advertising and for iOS 14 devices facebook asked to enable the Advertising tracking flag. So to solve this issue I added this line in my App.js file.