解決!
我檢查了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];
}
它現在工作正常:)
你有沒有禁用沙箱模式? –
是的。它可以在模擬器上運行 –