我有一个应用程序,其中包含Facebook集成,有时一切正常,但现在我收到了一些邮件,说有些人无法使用Facebook登录。
现在我知道问题出在哪里了。
如果我没有通过我的Facebook账户设置登录,一切都正常,但是当我通过设置登录时,我总是在sessionStateChanged
函数中得到FBSessionStateClosedLoginFailed:
的情况。
我该怎么办?
以下是我的代码:
首先,当我点击使用Facebook登录时,我使用此函数:
- (void)facebookLoginFunction {
if ([self checkInternet]==TRUE) {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(sessionStateChanged:) name:FBSessionStateChangedNotification object:nil];
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication]delegate];
// The person using the app has initiated a login, so call the openSession method
// and show the login UX if necessary.
[appDelegate openSessionWithAllowLoginUI:YES];
}
}
并且在Delegate中有一个名为sessionStateChanged的函数。
- (void)sessionStateChanged:(FBSession *)session state:(FBSessionState) state error:(NSError *)error{
switch (state) {
case FBSessionStateOpen:
if (!error) {
// We have a valid session
NSLog(@"User session found");
}
break;
case FBSessionStateClosed: NSLog(@"User session closed");
case FBSessionStateClosedLoginFailed:{ NSLog(@"Login failed");
[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];
}
}
我真心希望你能帮助我,因为我不理解这个疯狂的问题。谢谢!
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url { return [FBSession.activeSession handleOpenURL:url]; }
和- (void)applicationDidBecomeActive:(UIApplication *)application { [FBSession.activeSession handleDidBecomeActive]; }
- Skrew