簡體   English   中英

Facebook登錄可在iPhone模擬器上使用,但不能在iPhone設備上使用

[英]facebook login works on iphone simulator but not on iphone device

在我的應用中,我想從Facebook上拍照。 所以我用了facebook ios sdk。 我可以從以下代碼進行授權:

 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設備上登錄。 當我嘗試登錄時,它將打開一個野生動物園,然后顯示消息“正在更新”。 然后它將未經授權重定向。 獲取為nil的訪問令牌。 所以我不能撤回圖像。

請幫我。

編輯

謝謝大家。最后我解決了我的問題。 這是因為我在Facebook開發者帳戶設置中啟用了沙箱模式。 當我禁用沙箱模式時,它可以正常工作。

嘗試清除“ Safari”的Cookie和緩存,然后轉到“設置”。 另外,如果您不希望應用程序重定向到Safari,只需在info.plist中不提供類似於“ fb-AppId-”之類的URL方案,它將打開一個用於登錄的彈出窗口

我遇到了類似的問題,並通過在此網站中編寫了幾個解決方案來解決了這個問題。 首先,我在info plist上取消了url方案。 因此,現在我的應用程序在我的注冊頁面中打開了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
         }
     }];
  }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM