4

私のiPhoneアプリでは、ボタンをクリックするとFacebookアプリのようにFacebookログインにリダイレクトされます。ログイン後、アプリにリダイレクトします。

私はこのコードを使用しています

NSArray *permissions =
[NSArray arrayWithObjects:@"user_photos", @"friends_photos",@"email", nil];

[FBSession openActiveSessionWithReadPermissions:permissions
                                   allowLoginUI:YES
                              completionHandler:
 ^(FBSession *session,
   FBSessionState state, NSError *error) {

     if(!error)
     {
         NSLog(@" hi im sucessfully lloged in");
     }
 }];
4

1 に答える 1

5

あなたのAppDelegateでメソッドを変更します

- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url  
{

NSString *urlString = [url absoluteString];

if ([urlString hasPrefix:@"fb://xxxxxxxxxxxx"]) {
    [FBSession.activeSession handleOpenURL:url];
    returnValue = YES;
}

return returnValue;
}  

また

ただし、これはIOS 6ではトリガーされないことに注意してください。ios6では、次のメソッドがトリガーされます。

 - (BOOL)application:(UIApplication *)application
        openURL:(NSURL *)url
 sourceApplication:(NSString *)sourceApplication
     annotation:(id)annotation {

return [FBSession.activeSession handleOpenURL:url];
 }

ログインまたは切断によりセッションの状態が変化した場合、FBsessionは次のメソッドを呼び出し、ケースを処理する必要があります。

- (void)sessionStateChanged:(FBSession *)session
                  state:(FBSessionState)state
                  error:(NSError *)error {
switch (state) {
    case FBSessionStateOpen: {
        //update permissionsArrat
        [self retrieveUSerPermissions];

        if (!needstoReopenOldSession) {
            //First User information
            [self getUserInformation:nil];
        }

        NSNotification *authorizationNotification = [NSNotification notificationWithName:facebookAuthorizationNotification object:nil];
        [[NSNotificationCenter defaultCenter] postNotification:authorizationNotification];

    }
    case FBSessionStateClosed: {
        break;
    }
    case FBSessionStateClosedLoginFailed: {
        [FBSession.activeSession closeAndClearTokenInformation];
        break;
    }
    default:
        break;
}

if (error) {
    NSNotification *authorizationNotification = [NSNotification notificationWithName:faceBookErrorOccuredNotification object:nil];
    [[NSNotificationCenter defaultCenter] postNotification:authorizationNotification];
}
}
于 2013-01-23T05:16:05.540 に答える