我创建了一个Facebook应用程序。我在sandbox mode
进行了测试,结果没问题。
现在我想让其他人在手机上测试此应用,因此我关闭了sandbox mode
,我发现iPhone-5
用户无法登录,但在android
中仍能正常使用电话
这是错误日志 -
会话创建错误:错误Domain = com.facebook.sdk Code = 2“操作无法完成。(com.facebook.sdk错误2)”UserInfo = 0x16561ad0
我检查了我的bundle id
和app id
,它没有出错
答案 0 :(得分:7)
这对我有用:
转到iPhone的设置应用。 打开您的Facebook设置 向下滚动到您的应用,确保您的应用允许Facebook互动。 这可能发生在任何设备上,因此在您的应用程序中,您必须确保正确处理此错误。我估计你向用户提供反馈为何登录Facebook失败并要求用户在他们的设备上检查他们的Facebook设置。
- (void)facebookSessionStateChanged:(FBSession *)session state:(FBSessionState)state error:(NSError *)error{ switch (state) {
case FBSessionStateOpen:
// handle successful login here
case FBSessionStateClosed:
case FBSessionStateClosedLoginFailed:
[FBSession.activeSession closeAndClearTokenInformation];
// handle error here, for example by showing an alert to the user
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Could not login with Facebook"
message:@"Facebook login failed. Please check your Facebook settings on your phone."
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
break;
default:
break;
}
答案 1 :(得分:1)
我使用了以下方式并为我工作:
-(void)openFacebookAuthentication
{
NSArray *permission = [NSArray arrayWithObjects:kFBEmailPermission,kFBUserPhotosPermission,kFBUserPublicPermission,kFBUserLikePermission, nil];
FBSession *session = [[FBSession alloc] initWithPermissions:permission];
[FBSession setActiveSession: [[FBSession alloc] initWithPermissions:permission]];
[[FBSession activeSession] openWithBehavior:FBSessionLoginBehaviorForcingWebView completionHandler:^(FBSession *session, FBSessionState status, NSError *error) {
switch (status) {
case FBSessionStateOpen:
[self likeFaceBook];
break;
case FBSessionStateClosedLoginFailed: {
// prefer to keep decls near to their use
// unpack the error code and reason in order to compute cancel bool
NSString *errorCode = [[error userInfo] objectForKey:FBErrorLoginFailedOriginalErrorCode];
NSString *errorReason = [[error userInfo] objectForKey:FBErrorLoginFailedReason];
BOOL userDidCancel = !errorCode && (!errorReason || [errorReason isEqualToString:FBErrorLoginFailedReasonInlineCancelledValue]);
if(error.code == 2) {
UIAlertView *errorMessage = [[UIAlertView alloc] initWithTitle:kFBAlertTitle
message:kFBAuthenticationErrorMessage
delegate:nil
cancelButtonTitle:kOk
otherButtonTitles:nil];
[errorMessage performSelectorOnMainThread:@selector(show) withObject:nil waitUntilDone:YES];
errorMessage = nil;
}
}
break;
// presently extension, log-out and invalidation are being implemented in the Facebook class
default:
break; // so we do nothing in response to those state transitions
}
}];
permission = nil;
}