ios - 苹果在Facebook登录时拒绝应用程序

标签 ios facebook-graph-api

我在我的应用程序中使用 facebook 登录,并从 facebook 获取用户名和个人资料图片。我已经测试过,它在我这边运行良好,但苹果已经拒绝了两次。我最后没有发现任何错误。

这是苹果团队的错误:- "我们仍然发现您的应用程序在运行 iOS 7.1 的 iPad Air 和运行 iOS 7.1 的 iPhone 5s 上,在 Wi-Fi 和蜂窝网络上进行审查时存在一个或多个错误,这不符合 App Store 审查指南。 具体来说,当我们点击登录到 Facebook 时,我们收到消息说它想要连接,当我们点击确定时,它不会前进并与 Facebook 连接。 "

这是我的代码

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
 {
UIWindow *window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window = window;

self.login=[[ViewController alloc]init];
_nav = [[UINavigationController alloc] initWithRootViewController:self.login];



self.window.rootViewController = _nav;
[self.window makeKeyAndVisible];
// Override point for customization after application launch.

// Whenever a person opens the app, check for a cached session
if (FBSession.activeSession.state == FBSessionStateCreatedTokenLoaded) {
    NSLog(@"Found a cached session");
    // If there's one, just open the session silently, without showing the user the login UI
    [FBSession openActiveSessionWithReadPermissions:@[@"basic_info", @"email", @"user_likes"]
                                       allowLoginUI:NO
                                  completionHandler:^(FBSession *session, FBSessionState state, NSError *error) {
                                      // Handler for session state changes
                                      // This method will be called EACH time the session state changes,
                                      // also for intermediate states and NOT just when the session open
                                      [self sessionStateChanged:session state:state error:error];

                                      switch (state) {
                                          case FBSessionStateOpen:
                                              [[FBRequest requestForMe] startWithCompletionHandler:^(FBRequestConnection *connection, NSDictionary<FBGraphUser> *user, NSError *error) {
                                                  if (error) {

                                                      NSLog(@"error:%@",error);


                                                  }
                                                  else
                                                  {
                                                      // retrive user's details at here as shown below


                                                      NSUserDefaults *storeData=[NSUserDefaults standardUserDefaults];
                                                      [storeData setObject:user.id forKey:@"user_id"];
                                                      [storeData setObject:user.name forKey:@"name"];

                                                  }
                                              }];
                                              break;

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

                                          default:
                                              break;
                                      }



                                  }];

    // If there's no cached session, we will show a login button
} else {
    //UIButton *loginButton = [self.login loginButton];
    //[loginButton setTitle:@"Log in with Facebook" forState:UIControlStateNormal];
}
return YES;


  }

  - (void)applicationWillResignActive:(UIApplication *)application
 {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
  }

 - (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.
}


 // This method will handle ALL the session state changes in the app
 - (void)sessionStateChanged:(FBSession *)session state:(FBSessionState) state error:(NSError *)error
 {
// If the session was opened successfully
if (!error && state == FBSessionStateOpen){
    NSLog(@"Session opened");
    // Show the user the logged-in UI
    [self userLoggedIn];
    return;
}
if (state == FBSessionStateClosed || state == FBSessionStateClosedLoginFailed){
    // If the session is closed
    NSLog(@"Session closed");
    // Show the user the logged-out UI
    [self userLoggedOut];
}

// Handle errors
if (error){
    NSLog(@"Error");
    NSString *alertText;
    NSString *alertTitle;
    // If the error requires people using an app to make an action outside of the app in order to recover
    if ([FBErrorUtility shouldNotifyUserForError:error] == YES){
        alertTitle = @"Something went wrong";
        alertText = [FBErrorUtility userMessageForError:error];
        [self showMessage:alertText withTitle:alertTitle];
    } else {

        // If the user cancelled login, do nothing
        if ([FBErrorUtility errorCategoryForError:error] == FBErrorCategoryUserCancelled) {
            NSLog(@"User cancelled login");

            // Handle session closures that happen outside of the app
        } else if ([FBErrorUtility errorCategoryForError:error] == FBErrorCategoryAuthenticationReopenSession){
            alertTitle = @"Session Error";
            alertText = @"Your current session is no longer valid. Please log in again.";
            [self showMessage:alertText withTitle:alertTitle];

            // For simplicity, here we just show a generic message for all other errors
            // You can learn how to handle other errors using our guide: https://developers.facebook.com/docs/ios/errors
        } else {
            //Get more error information from the error
            NSDictionary *errorInformation = [[[error.userInfo objectForKey:@"com.facebook.sdk:ParsedJSONResponseKey"] objectForKey:@"body"] objectForKey:@"error"];

            // Show the user an error message
            alertTitle = @"Something went wrong";
            alertText = [NSString stringWithFormat:@"Please retry. \n\n If the problem persists contact us and mention this error code: %@", [errorInformation objectForKey:@"message"]];
            [self showMessage:alertText withTitle:alertTitle];
        }
    }
    // Clear this token
    [FBSession.activeSession closeAndClearTokenInformation];
    // Show the user the logged-out UI
    [self userLoggedOut];
}
  }

// Show the user the logged-out UI
- (void)userLoggedOut
 {
// Set the button title as "Log in with Facebook"
// UIButton *loginButton = [self.login loginButton];
//[loginButton setTitle:@"Log in with Facebook" forState:UIControlStateNormal];

// Confirm logout message
      //[self showMessage:@"You're now logged out" withTitle:@""];
  }

 // Show the user the logged-in UI
- (void)userLoggedIn
 {
// Set the button title as "Log out"
// UIButton *loginButton = self.login.loginButton;
//[loginButton setTitle:@"Log out" forState:UIControlStateNormal];

     FrontViewController *v=[[FrontViewController alloc]init];
RearViewController *rearViewController = [[RearViewController alloc] init];

UINavigationController *frontNavigationController = [[UINavigationController alloc] initWithRootViewController:v];
UINavigationController *rearNavigationController = [[UINavigationController alloc] initWithRootViewController:rearViewController];


SWRevealViewController *revealController = [[SWRevealViewController alloc] initWithRearViewController:rearNavigationController frontViewController:frontNavigationController];
revealController.delegate = self;


[self.nav pushViewController:revealController animated:YES];



[self showMessage:@"You're now logged in" withTitle:@"Welcome!"];

  }

  // Show an alert message
  - (void)showMessage:(NSString *)text withTitle:(NSString *)title
  {
[[[UIAlertView alloc] initWithTitle:title
                            message:text
                           delegate:self
                  cancelButtonTitle:@"OK!"
                  otherButtonTitles:nil] show];
 }

   // During the Facebook login flow, your app passes control to the Facebook iOS app or Facebook in a mobile browser.
  // After authentication, your app will be called back with the session information.
  // Override application:openURL:sourceApplication:annotation to call the FBsession object that handles the incoming URL

     - (BOOL)application:(UIApplication *)application
        openURL:(NSURL *)url
  sourceApplication:(NSString *)sourceApplication
     annotation:(id)annotation
 {
  return [FBSession.activeSession handleOpenURL:url];
}

- (void)applicationDidBecomeActive:(UIApplication *)application
{

// Handle the user leaving the app while the Facebook login dialog is being shown
// For example: when the user presses the iOS "home" button while the login dialog is active
   [FBAppCall handleDidBecomeActive];
}

在我的 View Controller 中

  - (IBAction)buttonTouched:(id)sender
 {
  // If the session state is any of the two "open" states when the button is clicked
  if (FBSession.activeSession.state == FBSessionStateOpen
    || FBSession.activeSession.state == FBSessionStateOpenTokenExtended) {

    // Close the session and remove the access token from the cache
    // The session state handler (in the app delegate) will be called automatically
    [FBSession.activeSession closeAndClearTokenInformation];

    // If the session state is not any of the two "open" states when the button is clicked
} else {
    // Open a session showing the user the login UI
    // You must ALWAYS ask for basic_info permissions when opening a session
    [FBSession openActiveSessionWithReadPermissions:@[@"basic_info", @"email", @"user_likes"]
                                       allowLoginUI:YES
                                  completionHandler:
     ^(FBSession *session, FBSessionState state, NSError *error) {

         // Retrieve the app delegate
         AppDelegate* appDelegate = [UIApplication sharedApplication].delegate;
         // Call the app delegate's sessionStateChanged:state:error method to handle session state changes
         [appDelegate sessionStateChanged:session state:state error:error];

         switch (state) {
             case FBSessionStateOpen:
                 [[FBRequest requestForMe] startWithCompletionHandler:^(FBRequestConnection *connection, NSDictionary<FBGraphUser> *user, NSError *error) {
                     if (error) {

                         NSLog(@"error:%@",error);


                     }
                     else
                     {
                         // retrive user's details at here as shown below
                         NSLog(@"FB user first name:%@",user.first_name);



                             NSUserDefaults *storeData=[NSUserDefaults standardUserDefaults];
                            [storeData setObject:user.id forKey:@"user_id"];
                            [storeData setObject:user.name forKey:@"name"];

                     }


                 }];
                 break;

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

             default:
                 break;
         }

     }];
}

最佳答案

您在 developer.facebook.com 上的应用是否公开并可供所有用户使用?

状态应该是这样的:
Facebook app satus

在其他情况下,如果您的应用处于开发者模式状态,则其他用户无法通过 Facebook 授权。

关于ios - 苹果在Facebook登录时拒绝应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23371975/

相关文章:

ios - 如何以编程方式在 TableView 页脚中为 UIView 设置约束?

facebook - Facebook API更改后如何获取用户头像

facebook - 如何使用 FQL 或 Graph API 检索仅包含一个标记用户的照片或照片?

docker - Facebook Graph API 和 Docker

iphone - 在服务器上的iPhone上使用单点登录权限

ios - 无法在 Xcode 10 中查找屏幕比例和意外的物理屏幕方向

使用自分配证书的IOS wkwebview

facebook - 如何使用广告帐户 ID 从 Facebook 图形 api 检索商务管理平台 ID

Facebook graph-api 获取链接统计信息

ios - 使用 audiokit 在 AKsequencer 中创建额外 MIDI 轨道的问题