私は自分のアプリに Facebook ログイン フローの例を使用しており、前のサンプル アプリではこのログイン プロセスは機能していましたが、エラー (com.facebook.sdk エラー 2.) が発生しました。私は iOS 6 でビルドしており、すべての ID とバンドル識別子が一致することを確認しました。
サンプルコード
appdelegate.m
- (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:
case FBSessionStateClosedLoginFailed:
[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];
NSLog(@"Login Failed");
[alertView show];
}
}
// Opens a Facebook session and optionally shows the login UX.
- (BOOL)openSessionWithAllowLoginUI:(BOOL)allowLoginUI {
NSArray *permissions = [[NSArray alloc] initWithObjects:
@"user_events",
@"user_activites",
@"user_birthday",
nil];
return [FBSession openActiveSessionWithReadPermissions:permissions
allowLoginUI:allowLoginUI
completionHandler:^(FBSession *session,
FBSessionState state,
NSError *error) {
NSLog(@"\nfb sdk error = %@", error);
[self sessionStateChanged:session
state:state
error:error];
}];
}
/*
* If we have a valid session at the time of openURL call, we handle
* Facebook transitions by passing the url argument to handleOpenURL
*/
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation {
// attempt to extract a token from the url
NSLog(@"Found FaceBook");
return [FBSession.activeSession handleOpenURL:url];
}
maincontroller.m
- (IBAction)authButtonAction:(id)sender {
NSLog(@"session open");
AppDelegate *appDelegate = (AppDelegate*)
[[UIApplication sharedApplication] delegate];
// If the user is authenticated, log out when the button is clicked.
// If the user is not authenticated, log in when the button is clicked.
if (FBSession.activeSession.isOpen) {
[appDelegate closeSession];
} else {
// The user has initiated a login, so call the openSession method
// and show the login UX if necessary.
[appDelegate openSessionWithAllowLoginUI:YES];
}
}
- (void)sessionStateChanged:(NSNotification*)notification {
NSLog(@"Login Activated");
self.navigationItem.leftBarButtonItem = authButton;
if (FBSession.activeSession.isOpen) {
authButton = [[UIBarButtonItem alloc] init];
authButton.title=@"Login";
}else{
authButton =[[UIBarButtonItem alloc]init];
authButton.title=@"Logout";
}
}
何か案は?これは Facebook のバグですか、それとも何か不足していますか?