iOS 中的 Facebook 登录在首次尝试登录时未打开 Safari
Facebook login in iOS is not opening safari when attempting to login for the first time
我的应用程序 登录屏幕,
第一次尝试 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
但永远不会调用回调块,而再次单击会调用回调处理程序。如有任何帮助,我们将不胜感激。
如果可行,您可以尝试一种解决方案!
将 FBSDKLoginManager *manager
声明为实例变量或 属性 并在 viewDidload
中初始化它,例如
FBSDKLoginManager *manager = [FBSDKLoginManager new];
然后用!!可能是本地声明的原因!
我的应用程序 登录屏幕,
第一次尝试 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
但永远不会调用回调块,而再次单击会调用回调处理程序。如有任何帮助,我们将不胜感激。
如果可行,您可以尝试一种解决方案!
将 FBSDKLoginManager *manager
声明为实例变量或 属性 并在 viewDidload
中初始化它,例如
FBSDKLoginManager *manager = [FBSDKLoginManager new];
然后用!!可能是本地声明的原因!