2013-05-02 200 views
0

在我的應用程序中,我想從Facebook拍照。所以我用facebook ios sdk。我可以從以下代碼授權:facebook登錄在iphone模擬器上工作,但不在iphone設備上

if (appDelegate.session.isOpen) { 

      //[appDelegate.session closeAndClearTokenInformation]; 
      [self retrieveAlbums]; 

     } else { 
      if (appDelegate.session.state != FBSessionStateCreated) { 
       // Create a new, logged out session. 
       appDelegate.session = [[FBSession alloc] init]; 
      } 

      // if the session isn't open, let's open it now and present the login UX to the user 
      [appDelegate.session openWithCompletionHandler:^(FBSession *session, 
                  FBSessionState status, 
                  NSError *error) { 
       // and here we make sure to update our UX according to the new session state 
       //NSLog(@"%@",session.accessTokenData.accessToken); 
       [self retrieveAlbums]; 
      }]; 

它在iPhone模擬器上正常工作。但我無法登錄我的iPhone 4設備。 當我試圖登錄時,它會打開一個safari,然後顯示消息更新。 然後它會在未經授權的情況下重定向。訪問令牌檢索爲零。所以我無法檢索圖像。

請幫幫我。

編輯

感謝大家。最後我解決我的問題。這是因爲我在Facebook開發人員帳戶設置中啓用了沙盒模式。當我禁用沙箱模式時,它正常工作。

+0

什麼是iPhone4的 – 2013-05-02 12:21:15

+0

IOS版本iOS版本6.1.2是嘿 – manujmv 2013-05-02 12:25:11

+0

@manujmv,我有類似的問題。禁用沙箱模式並不意味着這個問題就解決了,因爲我們遲早會啓用它。 – 2014-06-10 11:13:11

回答

1

嘗試清除Safari瀏覽器的Cookie和緩存,然後轉到設置。 此外,如果你不希望應用程序重定向到Safari,只是不提供您的info.plist中的URL計劃,就像「fb-AppId-」,它會打開彈出登錄

0

我有類似的問題,並通過在本網站上撰寫幾個解決方案來解決它。首先我擺脫了我的信息plist的網址方案。所以現在我的應用程序在我的註冊頁面裏打開了facebook登錄對話框。這是一件好事,因爲它不會來回Safari瀏覽器的Facebook身份驗證,你留在應用程序內。我做的第二件事是,在我的Facebook登錄代碼中加入錯誤處理機制。所以如果用facebook登錄失敗,它使用另一種登錄策略。

這是我的代碼。

- (void)loginView:(FBLoginView *)loginView handleError:(NSError *)error { 

     NSArray *permissions = [[NSArray alloc] initWithObjects: 
         @"public_profile", @"user_friends", @"email", 
         nil]; 
     FBSession *session = [[FBSession alloc] initWithPermissions:permissions]; 
     [FBSession setActiveSession:session]; 

     [self openSessionWithAllowLoginUI:YES completionHandler:^(FBSession *session, FBSessionState status, NSError *error) { 
     if (!error && status == FBSessionStateOpen) { 
      NSString *token = session.accessTokenData.accessToken; 
      NSLog(@"Logged in! - Token -- %@", token); 
     } else { 
      NSLog(@"Something wrong happened");//you can check the error code here 
     } 
    }]; 
    } 
相關問題