2014-01-21 51 views
10

在我的應用程序有三種登錄方式。其中之一是與Facebook登錄。但是,當我點擊Facebook按鈕時,它會詢問我是否具有訪問權限,當點擊OK時,它會返回錯誤FBErrorCategoryUserCancelled。這不會發生在每個設備上,它發生在某些設備上。這裏是我的代碼 -總是返回錯誤FBErrorCategoryUserCancelled與我的應用程序中的Facebook登錄

if ([[FBSession activeSession]isOpen]) { 
    /* 
    * if the current session has no publish permission we need to reauthorize 
    */ 
    if ([[[FBSession activeSession]permissions]indexOfObject:@"publish_actions"] == NSNotFound) { 

     [[FBSession activeSession] requestNewPublishPermissions:[NSArray arrayWithObject:@"publish_actions"] defaultAudience:FBSessionDefaultAudienceFriends 
               completionHandler:^(FBSession *session,NSError *error){ 

                [ProgressHUD dismiss]; 
                self.view.userInteractionEnabled = YES; 

               }]; 

    }else{ 

     [self fetchUserDetails]; 
    } 

}else{ 
    /* 
    * open a new session with publish permission 
    */ 
    [FBSession openActiveSessionWithPublishPermissions:[NSArray arrayWithObject:@"publish_actions"] 
             defaultAudience:FBSessionDefaultAudienceOnlyMe 
              allowLoginUI:YES 
            completionHandler:^(FBSession *session, FBSessionState status, NSError *error) { 
             if (!error && status == FBSessionStateOpen) { 

              [self fetchUserDetails]; 

             }else{ 

              NSLog(@"error"); 

              if ([FBErrorUtility shouldNotifyUserForError:error]) { 
               alertTitle = @"Facebook Error"; 
               alertMessage = [FBErrorUtility userMessageForError:error]; 

               // This code will handle session closures that happen outside of the app 
               // You can take a look at our error handling guide to know more about it 
               // https://developers.facebook.com/docs/ios/errors 
              } else if ([FBErrorUtility errorCategoryForError:error] == FBErrorCategoryAuthenticationReopenSession) { 
               alertTitle = @"Session Error"; 
               alertMessage = @"Your current session is no longer valid. Please log in again."; 

               // If the user has cancelled a login, we will do nothing. 
               // You can also choose to show the user a message if cancelling login will result in 
               // the user not being able to complete a task they had initiated in your app 
               // (like accessing FB-stored information or posting to Facebook) 

              } else if ([FBErrorUtility errorCategoryForError:error] == FBErrorCategoryUserCancelled) { 
               NSLog(@"user cancelled login"); 

               alertTitle = @"Facebook Error"; 
               alertMessage = @"System login cancelled"; 

               // For simplicity, this sample handles other errors with a generic message 
               // You can checkout our error handling guide for more detailed information 
               // https://developers.facebook.com/docs/ios/errors 
              } else { 
               alertTitle = @"Something went wrong"; 
               alertMessage = @"Please try again later."; 
               NSLog(@"Unexpected error:%@", error); 
              } 

               [[[UIAlertView alloc] initWithTitle:alertTitle 
                      message:alertMessage 
                      delegate:nil 
                    cancelButtonTitle:@"OK" 
                    otherButtonTitles:nil] show]; 

              [ProgressHUD dismiss]; 
              self.view.userInteractionEnabled = YES; 

             } 
            }]; 
} 

任何幫助將不勝感激。謝謝。

回答

0

對我而言,這是因爲facebook應用程序的沙盒模式仍然處於開啓狀態,因此會導致FBErrorCategoryUserCancelled適用於任何不是該應用程序的管理員/開發人員/測試人員的人員。

要關閉沙盒模式在Facebook上,去 https://developers.facebook.com/apps/YOUR_FACEBOOK_APP_ID/review-status/

看到它說:「你想將這個應用程式及所有Live功能,提供給廣大市民呢?」,使之成爲YES 。 (您可能需要插入聯繫人電子郵件才能訪問此選項)。或者,如果您不想讓應用程序公開,請邀請測試人員成爲應用程序的管理員/開發人員/測試人員。該人需要接受你的邀請才能使用它。

+0

謝謝你的回答。但我已經把它變成了YES。有沒有其他辦法? – Smita

相關問題