2014-04-29 112 views
0

我在我的應用程序中使用Facebook登錄並從Facebook獲取用戶名和個人資料照片。我已經測試過,並且在我的最後工作正常,但蘋果拒絕了兩次。我沒有在我的最後發現任何錯誤。 「蘋果在Facebook上的應用程序拒絕登錄

這是由蘋果團隊提供的錯誤: - 」我們仍然發現您的應用在iPad Air上運行iOS 7.1和運行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; 
     } 

    }]; 
} 

}

+0

當你運行你的應用程序並點擊登錄到Facebook然後點擊連接,它會繼續並登錄,還是停在那裏? –

+0

當我這樣做,它繼續與Facebook,我能夠進入應用程序和分享照片到我的臉書。 –

+0

您是否嘗試刪除您的測試版本並重新安裝新版本以查看是否可以複製它們的問題? – Logan

回答

1

是您的上developer.facebook.com應用公共和適用於所有用戶?

狀態應該是這樣的:
Facebook app satus

在其他情況下,如果你的應用程序有狀態Developer Mode然後其他用戶無法通過Facebook的授權。

+0

是的,它是公開的,可供所有用戶使用 –

相關問題