0

Facebook 登录在 iOS 模拟器上正常工作,但在设备 (iPhone 4) 上不工作。就它在模拟器上的工作而言,我认为 facebookId、权限、.... 都设置好了。

NSArray *permissions = [NSArray arrayWithObjects:@"email",nil];

[FBSession openActiveSessionWithReadPermissions:permissions allowLoginUI:YES completionHandler:^(FBSession *session, FBSessionState status, NSError *error) {
    [self sessionStateChanged:session state:status error:error];
}];

有什么帮助吗?谢谢

4

1 回答 1

0

解决了!!!

我检查了 FacebookSDK 中的 SessionLoginSample 并找到了解决方案。

我不得不将上面的代码更改为这个:

MyAppDelegate *appDelegate = [[UIApplication sharedApplication]delegate];
if (!appDelegate.session.isOpen || appDelegate.session.state != FBSessionStateCreated) {
    // Create a new, logged out session.
    appDelegate.session = [[FBSession alloc] init];
}

// if the session isn't open, let's open it now and present the login UX to the user
[appDelegate.session openWithCompletionHandler:^(FBSession *session,
                                                 FBSessionState status, 
                                                 NSError *error) {
    // and here we make sure to update our UX according to the new session state
    [self sessionStateChanged:session state:status error:error];
}];

我在 MyAppDelegate.h 中添加了一个属性

@property (strong, nonatomic) FBSession *session;

并更改 MyAppDelegate.m 中的方法

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication: (NSString *)sourceApplication annotation:(id)annotation
{
//  return [FBSession.activeSession handleOpenURL:url];
return [FBAppCall handleOpenURL:url sourceApplication:sourceApplication withSession:self.session];

}

它现在工作正常:)

于 2013-08-01T22:41:22.883 回答