Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
724 views
in Technique[技术] by (71.8m points)

objective c - FBConnect login, share with a webview?

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...