我的应用登录屏幕,
首次尝试时,Facebook登录按钮不会打开safari浏览器,而第二次尝试则无法正常工作。
以下是我尝试过的代码:
FBSDKLoginManager *manager = [FBSDKLoginManager new];
manager.loginBehavior = FBSDKLoginBehaviorBrowser;
NSArray *permissions = @[@"email",@"public_profile"];
[manager logInWithReadPermissions:permissions fromViewController:self handler:^(FBSDKLoginManagerLoginResult *result, NSError *error){
if(error) {
[self showAlertWith:@"Oops!" message:@"Login Failed, try again" handler:nil];
return;
}
if(result.isCancelled) {
[self showAlertWith:@"Oops!" message:@"Login Failed, try again" handler:nil];
return;
}else {
[[[FBSDKGraphRequest alloc] initWithGraphPath:@"me"
parameters:@{@"fields": @"picture, name, email"}]
startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id userinfo, NSError *error) {
if(!error) {
if([FBSDKAccessToken currentAccessToken]) {
[self makeGraphRequest];
}
}else {
EKLog(@"error %@", error);
}
}];
}
}];
第一次单击登录按钮调用loginWithReadPermission
但从不调用回调块,而再次单击,则调用回调处理程序。任何帮助将不胜感激。
答案 0 :(得分:2)
如果有效,你可以尝试一种解决方案!
将FBSDKLoginManager *manager
声明为实例变量或属性,并在viewDidload
中初始化,例如,
FBSDKLoginManager *manager = [FBSDKLoginManager new];
然后使用!!可能是因为当地宣言而发生的!