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

查看:25
本文介绍了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 登录 Web 视图中看到一个空白屏幕.
我还检查了我的一个使用旧 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.

任何想法都会受到赞赏.

Any idea will be appreciated.

提前谢谢你.

--
迈克尔.

推荐答案

在 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天全站免登陆