iOS Facebook框架login过程

我正在开发一个iOS应用程序,我正在提供通过Facebooklogin的function。 为此,我正在使用Facebook框架。 我已经通过了developers.facebook.com并实现了在那里描述的loginfunction。 FBlogin工作正常。 FBloginfunction是这样工作的:

  1. FB框架将尝试findFB应用程序,如果它存在,那么它将使用FB应用程序凭证进行authentication。

  2. 如果FB应用程序不存在,则会尝试使用iPhone设备设置FB凭证进行身份validation。

  3. 如果FB系统帐户不存在,则会打开Safari进行身份validation。

我希望在第三步,而不是safari Facebook Web视图popup。 以下是我正在使用的代码。

#import "AppDelegate.h" NSString *const FBSessionStateChangedNotification = @"com.sampleapp.facebook:FBSessionStateChangedNotification"; @implementation AppDelegate @synthesize loggedInUserID = _loggedInUserID, loggedInSession = _loggedInSession; static NSString* kAppId = **FBAPPID**; -(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; self.loginViewControlObj = [[LoginViewController alloc] init]; UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:self.loginViewControlObj]; self.navigationController = nav; self.navigationController.navigationBarHidden = YES; self.window.rootViewController = self.navigationController; [self.window makeKeyAndVisible]; return YES; } - (void)applicationWillResignActive:(UIApplication *)application { } - (void)applicationDidEnterBackground:(UIApplication *)application { // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. } - (void)applicationWillEnterForeground:(UIApplication *)application { // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background } - (void)applicationDidBecomeActive:(UIApplication *)application { [FBAppCall handleDidBecomeActive]; } - (void)applicationWillTerminate:(UIApplication *)application { [FBSession.activeSession close]; // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. } - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation { return [FBAppCall handleOpenURL:url sourceApplication:sourceApplication]; } #pragma mark - FB Methods /* * Callback for session changes. */ - (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"); [FBRequestConnection startForMeWithCompletionHandler:^(FBRequestConnection *connection, NSDictionary<FBGraphUser> *user, NSError *error) { if (!error) { self.loggedInUserID = user.id; self.loggedInSession = FBSession.activeSession; } }]; } 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]; [alertView show]; } } /* * Opens a Facebook session and optionally shows the login UX. */ - (void)openSessionWithAllowLoginUI:(BOOL)allowLoginUI { // Initialize a session object FBSession *session = [[FBSession alloc] initWithPermissions:[NSArray arrayWithObjects:@"basic_info", @"email", @"publish_stream", @"publish_actions", @"read_friendlists", nil]]; // Set the active session [FBSession setActiveSession:session]; // Open the session [session openWithBehavior:FBSessionLoginBehaviorWithFallbackToWebView completionHandler:^(FBSession *session, FBSessionState status, NSError *error) { [self sessionStateChanged:session state:status error:error]; }]; } /* * */ - (void) closeSession { [FBSession.activeSession closeAndClearTokenInformation]; } @end 

我从另一个控制器调用login,如果我没有在设备中的FB应用程序和系统帐户,然后打开Safari浏览器,而不是Web视图。

请帮我解决这个如果可能的话。