FBConnect login, web browsing sharing?

I am using FBConnect in my iOS project for user authorization (SSO).

After logging in, I sometimes need to open Webview to display user-specific dialogs, such as an application request dialog (an invitation to the application) and even open a friendโ€™s profile page in a web browser for the user of my application to view.

The problem is that Webview does not recognize the registered user and asks him to log in again, this is not very convenient.

Any ideas on how to share the registered auth / cookie key / something with a webview?

+4
source share
2 answers

You are probably faced with this situation. This is really frustrating.

Facebook iOS SDK does not save cookies for access

You can, if you want, force the iOS library to use your application to log in and allow the local application through UIWebview. This way you are logged in and use cookies. You will need to add the method to an existing Facebook object. Usually you call:

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

for authorization, which in turn calls a private method:

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

both parameters are 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 on Facebook.h so that I can name it, but 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 this with two BOOL parameters set to NO, and a local UIWebView appears in the library, which leaves me with cookies that work for the application.

+5
source

FBConnect returns the token to you, so that you have access to the FB API, not the FB website. Unfortunately, this is not logged in via UIWebView and sets the correct FB cookies.

Another strategy would be to modify the FBConnect source code to redirect to your own UIWebView instead of the standard FB popup window in the FB-APP process and only log in once. However, you will need to save the cookie state of the UIWebView.

I suggest you also take a look at http://www.getsocialize.com , which will help you manage social media integration.

Good luck

0
source

Source: https://habr.com/ru/post/927154/


All Articles