4
votes

I am using FBConnect in my iOS project to authorize the user (SSO).

Once logged in, I sometimes need to open a Webview in order to show the user specific dialogs such as the app request dialog (invite to app) and even to open a friend's profile page in a webview for my app user to browse.

The problem is that the Webview doesn't recognize the logged in user and asks him to login again, this is not very friendly.

Any ideas how to share the logged in auth key/cookie/something with the webview?

2

2 Answers

5
votes

You are likely running into this situation. It's really frustrating.

Facebook iOS SDK not storing cookies for access

You can, if you want, force the iOS library to use your app for login, and authorize through a UIWebview local to your app. You are thus logged in, and have cookies to use. You'll have to add a method to the existing Facebook object. Normally, you call:

- (void) authorize:(NSArray *)permissions 
          delegate:(id<FBSessionDelegate>)delegate

to authorize, which in turns calls the private method:

- (void)authorizeWithFBAppAuth:(BOOL)tryFBAppAuth
                    safariAuth:(BOOL)trySafariAuth

with both parameters set to YES.

You want to add a public method that calls the same private function but with both parameters set to NO. I added this method to Facebook.m and declared it in Facebook.h so I could call it however I like:

- (void)authorize:(NSArray *)permissions 
         tryFBApp:(BOOL) tryFBApp 
    trySafariAuth:(BOOL) trySafariAuth
         delegate:(id<FBSessionDelegate>)delegate {

    [_permissions release];
    _permissions = [permissions retain];

    _sessionDelegate = delegate;

    [self authorizeWithFBAppAuth:tryFBApp safariAuth:trySafariAuth];
}

I call that with the two BOOL parameters set to NO, and the library pops ups a local UIWebView that leaves me with cookies that work for the app.

0
votes

FBConnect returns you a token so that you have access to the FB API not the FB website. Unfortunately this doesn't login them in through a UIWebView and set the proper FB cookies.

Another strategy would be to change in the FBConnect source code to redirect to your own UIWebView instead of the standard FB pop-out to the FB-APP process and have them login only once. You would however have to persist the cookie state of the UIWebView.

I suggest that you also take a look at http://www.getsocialize.com which can help you manage social network integration.

good luck!