Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS: Connect to Facebook without leaving the app for authorization

I know that it was possible before the Graph API.

I work on an iPhone app that may not be in the background (one of the requirements).
In addition there is a login screen on the app launching.
Therefore it is not suitable to go to background in order to authenticate to Facebook and then return to the app and login once again each time the user wants to share something.

So, my question is if there is a way to authenticate with Facebook without leaving the app.

BTW, I have tried to use the old API.
It worked in the beginning but yesterday it stopped working.
I just see a blank screen inside the old Facebook login web view.
I have also checked one of my old apps that use that old Facebook Connect API and I get the same blank login screen in that app too.

Any idea will be appreciated.

Thank you in advance.

--
Michael.

like image 838
Michael Kessler Avatar asked Apr 14 '11 16:04

Michael Kessler


People also ask

How do I stay logged into Facebook on IOS?

Tap the Password field on the form, and enter your Facebook password. Tap the blue Log In button. This will sign you into your account, and open your News Feed. You will stay logged in on the app unless you manually log out, or delete the app and re-install it later.


1 Answers

In Facebook.m

- (void)authorizeWithFBAppAuth:(BOOL)tryFBAppAuth
                    safariAuth:(BOOL)trySafariAuth {
  NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                 _appId, @"client_id",
                                 @"user_agent", @"type",
                                 kRedirectURL, @"redirect_uri",
                                 @"touch", @"display",
                                 kSDKVersion, @"sdk",
                                 nil];

method comment out this

 UIDevice *device = [UIDevice currentDevice];
  if ([device respondsToSelector:@selector(isMultitaskingSupported)] && [device isMultitaskingSupported]) {
    if (tryFBAppAuth) {
      NSString *fbAppUrl = [FBRequest serializeURL:kFBAppAuthURL params:params];
      didOpenOtherApp = [[UIApplication sharedApplication] openURL:[NSURL URLWithString:fbAppUrl]];
    }

    if (trySafariAuth && !didOpenOtherApp) {
      NSString *nextUrl = [NSString stringWithFormat:@"fb%@://authorize", _appId];
      [params setValue:nextUrl forKey:@"redirect_uri"];

      NSString *fbAppUrl = [FBRequest serializeURL:loginDialogURL params:params];
      didOpenOtherApp = [[UIApplication sharedApplication] openURL:[NSURL URLWithString:fbAppUrl]];
    }
  }

This will prevent the app from going to background and show you the standard fb dialog.

like image 162
Marko Hlebar Avatar answered Oct 25 '22 18:10

Marko Hlebar