I'm setting up a React Native project using the FBSDK for login purpose.
Here's what I've done so far:
- I ran
npm install react-native-fbsdk --save
- I ran
react-native link
- I followed each step mentioned there: https://developers.facebook.com/docs/facebook-login/ios/
- I double checked using this video: https://www.youtube.com/watch?v=rAXVKapP5cM
However, I still get this red screen error:
Cannot read property logInWithReadPermissions of undefined
at FBLoginManager.js, line 77 (https://github.com/facebook/react-native-fbsdk/blob/master/js/FBLoginManager.js)
Here's my AppDelegate.m content:
#import "AppDelegate.h"
#import <FBSDKCoreKit/FBSDKCoreKit.h>
#import <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSURL *jsCodeLocation;
jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index.ios" fallbackResource:nil];
RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
moduleName:@"PegaseBuzzApp"
initialProperties:nil
launchOptions:launchOptions];
rootView.backgroundColor = [[UIColor alloc] initWithRed:1.0f green:1.0f blue:1.0f alpha:1];
[[FBSDKApplicationDelegate sharedInstance] application:application
didFinishLaunchingWithOptions:launchOptions];
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
UIViewController *rootViewController = [UIViewController new];
rootViewController.view = rootView;
self.window.rootViewController = rootViewController;
[self.window makeKeyAndVisible];
return YES;
}
- (void)applicationDidBecomeActive:(UIApplication *)application {
[FBSDKAppEvents activateApp];
}
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation {
return [[FBSDKApplicationDelegate sharedInstance] application:application
openURL:url
sourceApplication:sourceApplication
annotation:annotation];
}
@end
Here's my linked frameworks and binaries:
EDIT: on my project:
const FBSDK = require('react-native-fbsdk');
const {
LoginManager,
} = FBSDK;
Plus:
_onFBButtonPress () {
LoginManager.logInWithReadPermissions(['public_profile']).then(
function(result) {
if (result.isCancelled) {
alert('Login cancelled');
} else {
alert('Login success with permissions: '
+result.grantedPermissions.toString());
}
},
function(error) {
alert('Login fail with error: ' + error);
}
);
}
And:
<Button onPress={() => this._onFBButtonPress()} buttonStyle={'buttonFb'} labelStyle={'buttonFbText'} label={I18n.t('Login.btnConnectFB')}></Button>
What do I miss?
I just resolved the same error. For some reason "react-native link react-native-fbsdk" had finished for Android but not ios.
rnpm-install info Android module react-native-fbsdk is already linked rnpm-install info Linking react-native-fbsdk ios dependency rnpm-install info iOS module react-native-fbsdk has been successfully linked
Try rerunning and make sure you are linking with libRCTFBSDK.a