[英]Facebook iOS SDK Force Embedded Webview to request publish stream permission
我正在為一家餐廳制作iPad應用程序,客戶可以在其中登錄Facebook並張貼在牆上以獲取獎勵。 我需要該應用程序來強制用戶每次輸入其憑據。 我可以使登錄名與嵌入式Webview一起使用,但是請求權限后,我無法弄清楚如何通過嵌入式WebView進行操作。
當我嘗試使用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];
}];
}
那是一個錯誤,但已在最新版本的SDK(v3.10)中修復。
現在,會話將記住您用於打開會話的行為,並將其用於將來的權限請求。 請更新您使用的SDK。
我遇到同樣的問題,當請求發布權限然后再次顯示帶有簽名的授權對話框時(使用FBSessionLoginBehaviorForcingWebView行為登錄時)。 我已經在FBSession.m中修復它,只是在執行重新授權時不要刪除cookie
if (!isReauthorize)
{
[FBUtility deleteFacebookCookies];
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.