iOS:无需离开应用程序即可连接到 Facebook 进行授权 [英] iOS: Connect to Facebook without leaving the app for authorization

查看:30
本文介绍了iOS:无需离开应用程序即可连接到 Facebook 进行授权的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道在 Graph API 出现之前这是可能的.

I know that it was possible before the Graph API.

我正在开发一个可能不在后台的 iPhone 应用程序(要求之一).
此外,应用程序启动时还有一个登录屏幕.
因此,不适合在每次用户想要分享某些内容时都转到后台以对 Facebook 进行身份验证然后返回应用程序并再次登录.

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.

所以,我的问题是是否有一种方法可以在不离开应用程序的情况下通过 Facebook 进行身份验证.

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

顺便说一句,我尝试使用旧 API.
它在开始时有效,但昨天它停止工作.
我只是在旧的 Facebook 登录网页视图中看到一个空白屏幕.
我还检查了我的一个使用旧 Facebook Connect API 的旧应用程序,并且我在该应用程序中也看到了相同的空白登录屏幕.

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.

任何想法将不胜感激.

提前致谢.

--
迈克尔.

推荐答案

在 Facebook.m

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];

方法注释掉这个

 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]];
    }
  }

这将阻止应用进入后台并向您显示标准的 fb 对话框.

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

这篇关于iOS:无需离开应用程序即可连接到 Facebook 进行授权的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆