我有一个适用于 iOS5 及更高版本的应用程序,我正在尝试设置 Facebook 登录。当手机中集成了 Facebook 帐户时,一切正常。如果不是,它就不起作用。即使安装了 Facebook 应用程序也是如此。
安装应用程序后,它会打开应用程序,询问我是否有权访问相应的用户数据,然后返回我的应用程序但没有任何结果。没安装的时候也是这样。Safari 被打开了,问我授权,返回,什么都没有。
我遵循了 Facebook 登录教程中提到的所有步骤。这是只有我面临的问题吗?
编辑:这是请求的代码:
我像这样打开一个会话:
- (BOOL)openSessionWithAllowLoginUI:(BOOL)allowLoginUI {
NSArray *permissions = [[NSArray alloc] initWithObjects:
@"email",
nil];
return [FBSession openActiveSessionWithReadPermissions:permissions
allowLoginUI:allowLoginUI
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:
if (!error) {
// We have a valid session
NSLog(@"session opened");
FBRequest *me = [FBRequest requestForMe];
__block NSString *username = nil;
[me startWithCompletionHandler:^(FBRequestConnection *connection,
id result,
NSError *error) {
NSDictionary<FBGraphUser> *my = (NSDictionary<FBGraphUser> *) result;
// NSLog(@"User session found: %@", my.username);
username = my.username;
}];
// /fb_access/:access_token
}
break;
case FBSessionStateClosed:
if (!error) {
// We have a valid session
NSLog(@"User session closed");
}
case FBSessionStateClosedLoginFailed:
NSLog(@"login failed, %@", error);
[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];
}
}
有任何想法吗?