苹果在Facebook登录时拒绝苹果

时间:2014-04-29 17:59:47

标签: ios facebook-graph-api

我在我的应用程序中使用登录facebook并从facebook获取用户名和个人资料照片。我已经测试过,它在我的结束时工作正常,但苹果已经拒绝了两次。我最后没有发现任何错误。

这是Apple团队的错误: - "我们仍然发现,在运行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];
}

在我的视图控制器中

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

     }];
}

}

2 个答案:

答案 0 :(得分:1)

您的app.facebook.com上的应用是否公开,适用于所有用户?

状态应如下所示:
Facebook app satus

在其他情况下,如果您的应用的状态为Developer Mode,则其他用户无法通过Facebook进行授权。

答案 1 :(得分:0)

我有完全相同的问题。虽然是 Flutter 应用,但用例是一样的。

最后,一切都按预期进行

Facebook 应用的 iOS 和 Bundle ID 设置正确

FB 应用是公开的

但是苹果审核团队还是拒绝了。我要求他们提供更多屏幕截图,并且屏幕截图清楚地显示了 FB 弹出窗口的“继续”对话框。所以我不明白他们为什么拒绝它。