0

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.

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.

How do I keep this behaviour all within embedded webview?

This is the code I have right now:

// 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];
 }];
}
Ricky Gu
  • 585
  • 1
  • 4
  • 13

2 Answers2

0

That was a bug, but fixed in the latest version of the SDK (v3.10).

Now the Session will remember the behavior you used to open the session, and will use it for future permission requests. Please update the SDK you're using.

Ming Li
  • 15,672
  • 3
  • 37
  • 35
  • I upgraded to 3.10, it is working but the second time web view pops up it asks the user to sign in again. The user needs to sign in once for read permission, once for write permission. How do I fix this? – Ricky Gu Dec 18 '13 at 23:13
0

I faced with same issue, when request publish permissions then again shows authorization dialog with signing (When uses FBSessionLoginBehaviorForcingWebView behavior for login). I've fixed it in FBSession.m, just do not delete cookies when perform reauthorizations

if (!isReauthorize)
{
    [FBUtility deleteFacebookCookies];
}
Yevgeniy Logachev
  • 661
  • 1
  • 5
  • 11