首页 文章

React Native FBSDK登录 - 使用应用程序登录失败

提问于
浏览
0

我被定向到fb-app(因为它应该 . 到目前为止一切都很好) . 从这里我点击"Continue"(已经登录fb-app),然后我被重定向回到在应用程序中打开的facebook对话框(仍然很好) . 在这里,当我使用应用程序登录时,facebook对话会自动关闭 . 但是,在回调 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导致取消登录?

1 回答

  • 0

    我修好了它 .

    问题出在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;
    }
    

相关问题