当我运行 LoginUI 并单击取消按钮时,尝试登录而不是再次登录
我尝试在 iOS 上使用 Iphone4s / ios6.1.3 和 Facebook SDK 3.2.1,而不是取消登录可以再次登录。
iphone5发生了什么:
[FBSession.activeSession closeAndClearTokenInformation];
不行
这是我的代码:
- (void)sessionStateChanged:(FBSession *)session
state:(FBSessionState) state
error:(NSError *)error
{
switch (state) {
case FBSessionStateOpen:
if (!error) {
}
break;
case FBSessionStateClosed:
case FBSessionStateClosedLoginFailed:
[FBSession.activeSession closeAndClearTokenInformation];
break;
default:
break;
}
[[NSNotificationCenter defaultCenter]
postNotificationName:FBSessionStateChangedNotification
object:session];
if (error) {
UIAlertView *alertView = [[UIAlertView alloc]
initWithTitle:@"Error"
message:error.localizedDescription
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alertView show];
}
}
- (BOOL)openSessionWithAllowLoginUI:(BOOL)allowLoginUI {
return [FBSession openActiveSessionWithReadPermissions:nil
allowLoginUI:allowLoginUI
completionHandler:^(FBSession *session,
FBSessionState state,
NSError *error) {
[self sessionStateChanged:session
state:state
error:error];
}];
}
- (void) closeSession {
[FBSession.activeSession closeAndClearTokenInformation];
}
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation {
return [FBSession.activeSession handleOpenURL:url];
}
- (void)sessionStateChanged:(NSNotification*)notification {
if (FBSession.activeSession.isOpen) {
if (nil == self.facebook) {
self.facebook = [[Facebook alloc]
initWithAppId:FBSession.activeSession.appID
andDelegate:nil];
self.facebook.accessToken = FBSession.activeSession.accessTokenData.accessToken;
self.facebook.expirationDate = FBSession.activeSession.accessTokenData.expirationDate;
}
} else {
self.facebook = nil;
}
}
- (void) Loginfb {
AppDelegate *appDelegate =
[[UIApplication sharedApplication] delegate];
if (FBSession.activeSession.isOpen) {
} else {
[appDelegate openSessionWithAllowLoginUI:YES];
}
我该如何解决这个问题?Thanks in advance.