FaceBook API, login in-app

╄→尐↘猪︶ㄣ 提交于 2019-12-22 08:38:02

问题


I followed this guide and I've created my app successfully with Facebook integration.

What's the problem?

When the user has to do the login, the app quits in the browser (or in Facebook app, if is installed)

How do I keep authentication entirely in-app?


回答1:


The point of the oAuth login is that it doesn't happen within your application. It uses fast-app switching to perform the authentication in a trusted environment (either Safari or the Facebook application).

However, you can modify Facebook.m to do the authentication within your application, but you user's credentials will not be remembered. You can see that if your iOS device doesn't support multi-tasking, there is a backup login dialog.

Excerpt from Facebook.m (around line 160):

if ([device respondsToSelector:@selector(isMultitaskingSupported)] && [device isMultitaskingSupported]) {
    if (tryFBAppAuth) {
      NSString *scheme = kFBAppAuthURLScheme;
      if (_localAppId) {
        scheme = [scheme stringByAppendingString:@"2"];
      }
      NSString *urlPrefix = [NSString stringWithFormat:@"%@://%@", scheme, kFBAppAuthURLPath];
      NSString *fbAppUrl = [FBRequest serializeURL:urlPrefix params:params];
      didOpenOtherApp = [[UIApplication sharedApplication] openURL:[NSURL URLWithString:fbAppUrl]];
    }

    if (trySafariAuth && !didOpenOtherApp) {
      NSString *nextUrl = [self getOwnBaseUrl];
      [params setValue:nextUrl forKey:@"redirect_uri"];

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

// If single sign-on failed, open an inline login dialog. This will require the user to
// enter his or her credentials
if (!didOpenOtherApp) {
    [_loginDialog release];
    _loginDialog = [[FBLoginDialog alloc] initWithURL:loginDialogURL
                                      loginParams:params
                                         delegate:self];
    [_loginDialog show];
}

If you remove the first conditional and it's containing code and set didOpenOtherApp to NO, you can get the behavior you are looking for.




回答2:


To disable this behavior modify Facebook.m line 275 and set both options to NO.

- (void)authorize:(NSArray *)permissions {
  self.permissions = permissions;

  // with both options NO, authorization always happens in-app
  [self authorizeWithFBAppAuth:NO safariAuth:NO];
}


来源:https://stackoverflow.com/questions/6969680/facebook-api-login-in-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!