简体   繁体   English

适用于iOS的Facebook SDK 3.6 for iOS错误2

[英]Facebook SDK 3.6 for iOS error 2 on device

Facebook login works properly on iOS simulator, but it doesn't work on device (iPhone 4). Facebook登录可以在iOS模拟器上正常运行,但不能在设备(iPhone 4)上运行。 As far as it works on simulator, I think facebookId, permissions, .... are set up ok. 至于它在模拟器上的工作,我认为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];
}];

Any help? 有什么帮助吗? Thanks 谢谢

Solved!!! 解决了!!!

I checked SessionLoginSample in FacebookSDK and I found a solution. 我在FacebookSDK中检查了SessionLoginSample,并找到了解决方案。

I had to change above code to this one: 我不得不将上面的代码更改为此:

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];
}];

I added a property in MyAppDelegate.h 我在MyAppDelegate.h中添加了一个属性

@property (strong, nonatomic) FBSession *session;

and change a method in MyAppDelegate.m 并更改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];

}

It works fine now :) 现在工作正常:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM