我正在创建一个简单的 iOS 应用程序,它登录到 facebook,获取自己和朋友的详细信息,从 facebook 注销。
现在从 Facebook 登录并获取自己和朋友的详细信息工作正常,但我无法从 Facebook 完全注销。每当我注销然后重新登录时 - 我看到的是授权屏幕而不是 Facebook(Web)的身份验证登录屏幕。
下面是我的代码 - 你能看看我从登录到获取自己和朋友的详细信息以及从 Facebook 注销的步骤中是否有问题
1) 使用以下方法登录 Facebook
- (void)openSession
{
if(FBSession.activeSession.isOpen)
{
[FBSession openActiveSessionWithReadPermissions:nil
allowLoginUI:NO
completionHandler:
^(FBSession *session,
FBSessionState state, NSError *error)
{
[self sessionStateChanged:session state:state error:error];
}];
}
else
{
[FBSession openActiveSessionWithReadPermissions:nil
allowLoginUI:YES
completionHandler:
^(FBSession *session,
FBSessionState state, NSError *error)
{
[self sessionStateChanged:session state:state error:error];
}];
}
}
- (void)sessionStateChanged:(FBSession *)session
state:(FBSessionState) state
error:(NSError *)error
{
switch (state) {
case FBSessionStateOpen:
{
// Connection is Open
lblStatus.text = @"FBSessionStateOpen";
}
break;
case FBSessionStateClosed:
case FBSessionStateClosedLoginFailed:
{
[FBSession.activeSession closeAndClearTokenInformation];
// Connection is Closed / Login Failed
lblStatus.text = @"FBSessionStateClosed";
}
break;
default:
break;
}
}
2)使用以下方法获取自己的详细信息和朋友的详细信息
if (FBSession.activeSession.isOpen)
{
[[FBRequest requestForMe] startWithCompletionHandler:
^(FBRequestConnection *connection,
NSDictionary<FBGraphUser> *user,
NSError *error) {
if (!error) {
self.lblSelfDetails.text = user.name;
self.profilePicture.profileID = user.id;
}
}];
}
FBRequest *friendRequest = [FBRequest requestForGraphPath:@"me/friends?fields=name,birthday"];
[friendRequest startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error)
{
NSArray *data = [result objectForKey:@"data"];
for (FBGraphObject<FBGraphUser> *friend in data)
{
NSLog(@"%@:%@", [friend name],[friend birthday]);
}
}];
3)使用以下方法注销
- (IBAction)logout:(id)sender
{
[FBSession.activeSession closeAndClearTokenInformation];
}