gpt4 book ai didi

facebook - FBSDK FBSDKLoginManager 和 SFSafariViewController 不会关闭

转载 作者:行者123 更新时间:2023-12-02 14:42:04 28 4
gpt4 key购买 nike

我正在使用最新的 FBSDK,使用 FBSDKLoginManager 进行登录。我已经一切正常,但我无法弄清楚为什么 SFSafariViewController 在登录重定向后完全没有响应?

代码如下:

- (void) login:(void(^)(NSError *error, NSString * token)) completion {
FBSDKLoginManager * manager = [[FBSDKLoginManager alloc] init];
manager.loginBehavior = FBSDKLoginBehaviorNative;

if([FBSDKAccessToken currentAccessToken]) {
NSLog(@"already logged in");
NSLog(@"%@",[FBSDKAccessToken currentAccessToken]);
completion(nil,[FBSDKAccessToken currentAccessToken].tokenString);
return;
}

[manager logInWithReadPermissions:@[@"public_profile"] fromViewController:nil handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
dispatch_sync(dispatch_get_main_queue(), ^{
NSLog(@"%@",error);
NSLog(@"fb token: %@",[FBSDKAccessToken currentAccessToken].tokenString);
if(error) {
completion(error,nil);
return;
}
completion(nil,[FBSDKAccessToken currentAccessToken].tokenString);
});
}];
}

这就是发生的事情:

  1. SFSafariViewController 打开
  2. Facebook 提示登录
  3. 回调发生在 AppDelegate.openURL:options: (我通过调用 FBSDKApplicationDelegate.application:openURL:sourceApplication:annotation 返回)。
  4. Safari Web View Controller 不执行任何操作。

所以 SFSafariViewController 是白色/空白的。完成按钮不执行任何操作。而且我无法关闭它。

我也没有从 loginManager.loginWithReadPermissions 方法获得回调。

Empty SFSafariViewController

有人遇到过这种情况吗?

最佳答案

实际上它们是您需要实现的 2 种不同的 openURL* 回调,一种用于 iOS8,一种用于 iOS9:

@available(iOS 8, *)
func application(app: UIApplication, openURL url: NSURL, source: String?, annotation: AnyObject) -> Bool
{
return FBSDKApplicationDelegate.sharedInstance().application(app, openURL: url, sourceApplication: source, annotation: annotation)
}

@available(iOS 9, *)
func application(app: UIApplication, openURL url: NSURL, options: [String : AnyObject]) -> Bool
{
let source = options[UIApplicationOpenURLOptionsSourceApplicationKey] as? String // For ex: com.apple.SafariViewService from a SFSafariViewController
let annotation = options[UIApplicationOpenURLOptionsAnnotationKey]
return FBSDKApplicationDelegate.sharedInstance().application(app, openURL: url, sourceApplication: source, annotation: annotation)
}

关于facebook - FBSDK FBSDKLoginManager 和 SFSafariViewController 不会关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33486474/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com