我已经创建了一个facebook应用程序。我在sandbox mode上测试了它,它很好。
现在我想让其他人在手机上测试这个应用程序,所以我关闭了sandbox mode,我发现iPhone-5用户无法登录,但在android手机中仍然正常工作。
这是错误日志-
会话创建错误:错误Domain=com.facebook.sdk Code=2“操作无法完成。(com.facebook.sdk错误2.)UserInfo=0x16561ad0
我查了我的bundle id和app id,没出问题
发布于 2013-09-03 04:33:51
这对我起了作用:
转到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;
}发布于 2013-09-03 04:43:19
我使用了以下方法,并为我工作:
-(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;
}https://stackoverflow.com/questions/18584092
复制相似问题