Note that there are some explanatory texts on larger screens.

plurals
  1. POFacebook iOS SDK Force Embedded Webview to request publish stream permission
    text
    copied!<p>I'm making an iPad app for a restaurant, where customers can sign into Facebook and post on their wall to get a reward. I need the app to force the user to enter their credential every time. I was able to get the login to work with the embedded webview, but requesting permission I can't figure out how to do it via embedded. </p> <p>When I tried do it with safari redirect, safari will save the cookie and first user will still be logged when the second user uses the app. This behaviour isn't desirable for our use case.</p> <p>How do I keep this behaviour all within embedded webview? </p> <p>This is the code I have right now:</p> <pre><code>// 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]; }]; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload