如果我们从设置中有 Facebook 会话,FBLoginView 不会发出警报
Posted
技术标签:
【中文标题】如果我们从设置中有 Facebook 会话,FBLoginView 不会发出警报【英文标题】:FBLoginView not giving alert if we have Facebook session from settings 【发布时间】:2013-08-12 13:18:32 【问题描述】:如果我在 Safari 中没有 Facebook 会话或设备上的 Facebook 本机应用程序中没有 Facebook 会话,我正在使用 FBLoginView,此 FBLoginView 不采用 Facebook 会话表单设置
【问题讨论】:
【参考方案1】:使用对我来说工作正常:
-(void)LinkeToFaceBook:(NSString *)stringRequest
if ([HostSite checkServerConnected :kNetworkSuccess withFailureNote:kNetworkFailure])
if (!FBSession.activeSession.isOpen)
[FBSession.activeSession closeAndClearTokenInformation];
FBSession.activeSession=nil;
[self openFacebookAuthentication];
else
[self networkAlertShow];
-(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;
【讨论】:
我想在屏幕截图中显示警报我已经添加了 FBLoginView 类和 FB 登录视图的所有委托方法。以上是关于如果我们从设置中有 Facebook 会话,FBLoginView 不会发出警报的主要内容,如果未能解决你的问题,请参考以下文章
如何在请求会话之前检测用户是不是有 iOS 集成 Facebook 帐户设置?
Facebook SDK v3.5.2 - 从关闭的会话中请求权限
如何从 iOS 中的 Facebook SDK 获取用户信息?