React Native FBSDK 登录 - 使用应用程序登录失败
React Native FBSDK Login - Login with app fails
我正在对我的 react-native 应用程序实施 FB 登录。在浏览器-window 中使用email/password 登录时,FB-login 正在运行。 But when choosing "Log in with facebook-app", I'm being directed to the fb-app (as it should. Everything fine so far).从这里我点击 "Continue"(已经在 fb-app 中登录),然后我被重定向回在应用程序中打开的 facebook-dialogue(仍然很好)。在这里,当我使用该应用程序登录时,facebook-dialogue 会自动关闭,因为它应该这样做。但不是成功登录,而是在回调中触发 if(result.isCancelled)
。
这仅在使用 facebook-app 登录时发生。
登录码:
LoginManager.logInWithReadPermissions(["email", 'public_profile']).then(function(result){
if(result.isCancelled){
console.log('Login cancelled');
}
else{
// do login stuff.
}
}, function(error){
console.log("An error occured:");
console.log(error);
});
AppDelegate.m
#import "AppDelegate.h"
#import <FBSDKCoreKit/FBSDKCoreKit.h>
#import <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>
#import <React/RCTLinkingManager.h>
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[[FBSDKApplicationDelegate sharedInstance] application:application
didFinishLaunchingWithOptions:launchOptions];
NSURL *jsCodeLocation;
jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];
RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
moduleName:@"ntbscanpix"
initialProperties:nil
launchOptions:launchOptions];
rootView.backgroundColor = [[UIColor alloc] initWithRed:1.0f green:1.0f blue:1.0f 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
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation {
BOOL handled = [[FBSDKApplicationDelegate sharedInstance]
application:application
openURL:url
sourceApplication:sourceApplication
annotation:annotation
];
// Add any custom logic here.
return handled;
}
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
return [RCTLinkingManager application:application openURL:url options:options];
}
- (BOOL)application:(UIApplication *)application
continueUserActivity:(NSUserActivity *)userActivity
restorationHandler:(void (^)(NSArray * _Nullable))restorationHandler {
return [RCTLinkingManager application:application
continueUserActivity:userActivity
restorationHandler:restorationHandler];
}
@end
我在 appdelegate 中看到这个错误:
Conflicting parameter types in implementation of 'application:continueUserActivity:restorationHandler:': 'void (^ _Nonnull __strong)(NSArray<id<UIUserActivityRestoring>> * _Nullable __strong)' vs 'void (^__strong _Nonnull)(NSArray * _Nullable __strong)'
但我无法修复该错误。这可能是它无法从应用程序登录的原因吗?
如果不是,谁知道为什么使用facebook-app登录会导致登录取消?
我修好了。
问题出在 AppDelegate.m 中。该文件只能有一种 openUrl 方法。现在是两个,所以我不得不合并它们。这有效:
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation {
BOOL handledFB = [[FBSDKApplicationDelegate sharedInstance] application:application
openURL:url
sourceApplication:sourceApplication
annotation:annotation
];
BOOL handledRCT = [RCTLinkingManager application:application openURL:url sourceApplication:sourceApplication annotation:annotation];
return handledFB || handledRCT;
}
我正在对我的 react-native 应用程序实施 FB 登录。在浏览器-window 中使用email/password 登录时,FB-login 正在运行。 But when choosing "Log in with facebook-app", I'm being directed to the fb-app (as it should. Everything fine so far).从这里我点击 "Continue"(已经在 fb-app 中登录),然后我被重定向回在应用程序中打开的 facebook-dialogue(仍然很好)。在这里,当我使用该应用程序登录时,facebook-dialogue 会自动关闭,因为它应该这样做。但不是成功登录,而是在回调中触发 if(result.isCancelled)
。
这仅在使用 facebook-app 登录时发生。
登录码:
LoginManager.logInWithReadPermissions(["email", 'public_profile']).then(function(result){
if(result.isCancelled){
console.log('Login cancelled');
}
else{
// do login stuff.
}
}, function(error){
console.log("An error occured:");
console.log(error);
});
AppDelegate.m
#import "AppDelegate.h"
#import <FBSDKCoreKit/FBSDKCoreKit.h>
#import <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>
#import <React/RCTLinkingManager.h>
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[[FBSDKApplicationDelegate sharedInstance] application:application
didFinishLaunchingWithOptions:launchOptions];
NSURL *jsCodeLocation;
jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];
RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
moduleName:@"ntbscanpix"
initialProperties:nil
launchOptions:launchOptions];
rootView.backgroundColor = [[UIColor alloc] initWithRed:1.0f green:1.0f blue:1.0f 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
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation {
BOOL handled = [[FBSDKApplicationDelegate sharedInstance]
application:application
openURL:url
sourceApplication:sourceApplication
annotation:annotation
];
// Add any custom logic here.
return handled;
}
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
return [RCTLinkingManager application:application openURL:url options:options];
}
- (BOOL)application:(UIApplication *)application
continueUserActivity:(NSUserActivity *)userActivity
restorationHandler:(void (^)(NSArray * _Nullable))restorationHandler {
return [RCTLinkingManager application:application
continueUserActivity:userActivity
restorationHandler:restorationHandler];
}
@end
我在 appdelegate 中看到这个错误:
Conflicting parameter types in implementation of 'application:continueUserActivity:restorationHandler:': 'void (^ _Nonnull __strong)(NSArray<id<UIUserActivityRestoring>> * _Nullable __strong)' vs 'void (^__strong _Nonnull)(NSArray * _Nullable __strong)'
但我无法修复该错误。这可能是它无法从应用程序登录的原因吗?
如果不是,谁知道为什么使用facebook-app登录会导致登录取消?
我修好了。
问题出在 AppDelegate.m 中。该文件只能有一种 openUrl 方法。现在是两个,所以我不得不合并它们。这有效:
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation {
BOOL handledFB = [[FBSDKApplicationDelegate sharedInstance] application:application
openURL:url
sourceApplication:sourceApplication
annotation:annotation
];
BOOL handledRCT = [RCTLinkingManager application:application openURL:url sourceApplication:sourceApplication annotation:annotation];
return handledFB || handledRCT;
}