react-native-fbsdk "login with facebook app" 不触发回调



我正在使用react-native-fbsdk在我的React-Native应用程序中实现Facebook登录。我不知道为什么"使用Facebook应用程序登录"不起作用。当用户单击此按钮而不是在 Web 视图中输入其凭据时,LoginManager回调似乎永远不会被触发。

以下是发生的事情的视频: https://i.imgur.com/1XeJC1o.mp4

问题似乎是常见问题解答中的这个问题,但我相信我的AppDelegate.mInfo.plist文件设置正确。

#import "AppDelegate.h"
#import <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>
#import <SentryReactNative/RNSentry.h>
#import <GoogleMaps/GoogleMaps.h>
#import <react-native-branch/RNBranch.h>
#import <FBSDKCoreKit/FBSDKCoreKit.h>
#import <RNGoogleSignin/RNGoogleSignin.h>
#import <CodePush/CodePush.h>
#import <AppCenterReactNativeCrashes/AppCenterReactNativeCrashes.h>
#import <AppCenterReactNativeAnalytics/AppCenterReactNativeAnalytics.h>
#import <AppCenterReactNative/AppCenterReactNative.h>
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[RNBranch initSessionWithLaunchOptions:launchOptions isReferrable:YES];
NSURL *jsCodeLocation;
[AppCenterReactNativeCrashes registerWithAutomaticProcessing];  // Initialize AppCenter crashes
[AppCenterReactNativeAnalytics registerWithInitiallyEnabled:true];  // Initialize AppCenter analytics
[AppCenterReactNative register];  // Initialize AppCenter 
[GMSServices provideAPIKey:@"myAPiKey"];
[[FBSDKApplicationDelegate sharedInstance] application:application 
didFinishLaunchingWithOptions:launchOptions];
#ifdef DEBUG
jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];
#else
jsCodeLocation = [CodePush bundleURL];
#endif
RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation moduleName:@"downtown" initialProperties:nil launchOptions:launchOptions];
[RNSentry installWithRootView:rootView];
rootView.backgroundColor = [[UIColor alloc] initWithRed:0.02 green:0.02 blue:0.02 alpha:1];
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
UIViewController *rootViewController = [UIViewController new];
rootViewController.view = rootView;
self.window.rootViewController = rootViewController;
[self.window makeKeyAndVisible];
return YES;
}
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url 
options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation {
BOOL handledBranch = [RNBranch.branch application:application openURL:url sourceApplication:sourceApplication annotation:annotation];
BOOL handledFB = [[FBSDKApplicationDelegate sharedInstance] application:application openURL:url sourceApplication:sourceApplication annotation:annotation];
BOOL handledGoog = [RNGoogleSignin application:application openURL:url sourceApplication:sourceApplication annotation:annotation];
return handledBranch || handledFB || handledGoog;
}
- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray *restorableObjects))restorationHandler {
return [RNBranch continueUserActivity:userActivity];
}
@end

信息列表:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleDisplayName</key>
<string>BarCard</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0.1</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>barcard</string>
<string>downtown</string>
</array>
</dict>
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>fb$(myFbAppId)</string>
</array>
</dict>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLName</key>
<string>com.googleusercontent.apps.myGoogleKey</string>
<key>CFBundleURLSchemes</key>
<array>
<string>com.googleusercontent.apps.myGoogleKey</string>
</array>
</dict>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLIconFile</key>
<string></string>
<key>CFBundleURLName</key>
<string>com.barcard.downtown</string>
<key>CFBundleURLSchemes</key>
<array>
<string>com.barcard.downtown</string>
</array>
</dict>
</array>
<key>CFBundleVersion</key>
<string>28</string>
<key>CodePushDeploymentKey</key>
<string>$(CODEPUSH_KEY)</string>
<key>FacebookAppID</key>
<string>myFbAppId</string>
<key>FacebookDisplayName</key>
<string>BarCard by BarCard, Inc</string>
<key>ITSAppUsesNonExemptEncryption</key>
<false/>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>fbapi</string>
<string>fb-messenger-share-api</string>
<string>fbauth2</string>
<string>fbshareextension</string>
<string>message</string>
<string>readdle-spark</string>
<string>airmail</string>
<string>ms-outlook</string>
<string>googlegmail</string>
<string>inbox-gmail</string>
</array>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>localhost</key>
<dict>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
<true/>
</dict>
</dict>
</dict>
<key>UIBackgroundModes</key>
<array>
<string>remote-notification</string>
</array>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>armv7</string>
</array>
</dict>
</plist>

任何帮助将不胜感激!谢谢。

handleFacebookLogin = () => {   
var that = this
LoginManager.logInWithReadPermissions(['public_profile', 'email']).then(
function (result) {
// console.log(result)
if (result.isCancelled) {
alert('Login cancelled')
}
else {
AccessToken.getCurrentAccessToken()
.then((user) => {
//  alert("Facebook accessToken:n" + user.accessToken + "nnaccessTokenSource: " + user.accessTokenSource + "nnuserID: " + user.userID)
//  console.log(user);
return user
})
.then((user) => {
const responseInfoCallback = (error, result) => {
if (error) {
console.log(error)
// alert('Error fetching data: ' + error.toString());
} else {
console.log(result)
// alert('id: ' + result.id + 'nnname: ' + result.name + 'nnfirst_name: ' + result.first_name + 'nnlast_name: ' + result.last_name + 'nnemail: ' + result.email);
//  that.nextScreen()
console.log('Name='+result.name+'&lastname='+result.last_name+'&email='+result.email+'&token='+user.accessToken+'&providerName=facebook')

var data = JSON.stringify(result); // result => JSON
fetch(socialmedia login API

, {method: "POST"})
.then((response) => response.json())
.then((responseJson) => {
console.log(responseJson);
that.props.navigation.navigate('drawerStack', {param:responseJson[0]})
})
.catch((error) => {
alert(error)
console.error(error);
});
}
}
const infoRequest = new GraphRequest('/me', {
accessToken: user.accessToken,
parameters: {
fields: {
string: 'email,name,first_name,last_name'
}
}
}, responseInfoCallback);
// Start the graph request.
new GraphRequestManager()
.addRequest(infoRequest)
.start()
})
}
},
function (error) {
console.log(error)
Alert.alert('Login fail with error: ' + error)
}
)
}

最新更新