解决了!!!
我检查了 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];
}
它现在工作正常:)