iOS: Connect to Facebook without leaving the app for authorization

后端 未结 2 2140
栀梦
栀梦 2020-12-08 12:19

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 log

2条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-08 13:08

    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.

提交回复
热议问题