2013-11-26 21 views
0

我正在爲一家餐廳製作iPad應用程序,客戶可以登錄Facebook並張貼在牆上獲得獎勵。我需要應用程序強制用戶每次輸入他們的憑證。我能夠使登錄與嵌入式webview一起工作,但請求許可我不知道如何通過嵌入式來完成。Facebook iOS SDK強制嵌入式Web視圖請求發佈流權限

當我嘗試使用safari重定向時,safari會保存cookie,並且第二個用戶使用該應用時仍會記錄第一個用戶。這種行爲對我們的用例來說是不可取的。

如何在嵌入式webview中保持這種行爲?

這是我現在所擁有的代碼:

// Initialize a session object 
FBSession *session = [[FBSession alloc] init]; 
// Set the active session 
[FBSession setActiveSession:session]; 

// Open the session] 
[session openWithBehavior:FBSessionLoginBehaviorForcingWebView 
     completionHandler:^(FBSession *session, 
          FBSessionState status, 
          NSError *error) { 

      [session requestNewPublishPermissions:[NSArray arrayWithObject:@"publish_actions"] defaultAudience:FBSessionDefaultAudienceEveryone completionHandler:^(FBSession *session, NSError *error) { 
       [self publishStream]; 

      }]; 

}]; 


-(void)publishStream 
{ 
NSLog(@"publishing stream here"); 

[self publishStory]; 

[[FBSession activeSession] closeAndClearTokenInformation]; 
[[FBSession activeSession] close]; 
[FBSession setActiveSession:nil]; 

NSHTTPCookie *cookie; 
NSHTTPCookieStorage *storage = [NSHTTPCookieStorage sharedHTTPCookieStorage]; 
for (cookie in [storage cookies]) { 
    [storage deleteCookie:cookie]; 
} 
[[NSUserDefaults standardUserDefaults] synchronize]; 


} 


- (void)publishStory 
{ 
NSString *message = [NSString stringWithFormat:@"Having a great time at %@ and I just won a free %@", _restaurant_name, a_or_b? @"drink" : @"dessert"]; 
[FBRequestConnection 
startWithGraphPath:@"me/feed" 
parameters:[NSDictionary dictionaryWithObject:message forKey:@"message"] 
HTTPMethod:@"POST" 
completionHandler:^(FBRequestConnection *connection, 
        id result, 
        NSError *error) { 
    NSString *alertText; 
    if (error) { 
     alertText = [NSString stringWithFormat: 
         @"error: domain = %@, code = %d", 
         error.domain, error.code]; 
    } else { 
     alertText = @"You have checked in on Facebook, let the staff know to redeam your free treat!"; 
    } 
    // Show the result in an alert 
    [[[UIAlertView alloc] initWithTitle:nil 
           message:alertText 
           delegate:self 
         cancelButtonTitle:@"OK!" 
         otherButtonTitles:nil] 
     show]; 
}]; 
} 

回答

0

這是一個錯誤,但固定在SDK(V3.10)的最新版本。

現在會話將記住您用於打開會話的行爲,並將用於未來的權限請求。請更新您使用的SDK。

+0

我升級到3.10的時候只是不刪除cookies,這是工作,但第二次Web視圖彈出它要求用戶重新登錄。用戶需要登錄一次才能獲得讀取權限,一次用於寫入權限。我該如何解決? –

0

我面臨同樣的問題,當請求發佈權限,然後再次顯示授權對話與簽名(當使用FBSessionLoginBehaviorForcingWebView行爲進行登錄時)。我在FBSession.m固定它,執行重新授權

if (!isReauthorize) 
{ 
    [FBUtility deleteFacebookCookies]; 
}