ios - PFFacebookUtils logInInBackgroundWithReadPermissions : block: opens Facebook app instead of using system account

标签 ios parse-platform facebook-ios-sdk facebook-sdk-4.0 pffacebookutils

我已经升级到 ParseFacebookUtilsV4 并且我已经更新了我的登录代码:

[PFFacebookUtils logInInBackgroundWithReadPermissions:FACEBOOK_READ_PERMISSIONS block:^(PFUser *user, NSError *error) {
  ...
}];

但是,现在我的应用程序暂时切换到 Facebook 应用程序并返回。它使用 native Facebook 应用程序登录,同时在设置中仍然有一个有效的 iOS Facebook 帐户。如何让 PFFacebookUtils v4 在可用时使用系统 Facebook 帐户,并且仅在系统帐户不可用时才回退到 Facebook 应用程序?

最佳答案

来自 ParseFacebookUtilsV4 的头文件

PFFacebookUtils.h

...

/*! @abstract FBSDKLoginManager provides methods for configuring login behavior, default audience and managing Facebook Access Token.

@returns An instance of FBSDKLoginManager that is used by PFFacebookUtils. */

+ (FBSDKLoginManager *)facebookLoginManager;

因此,据推测,PFFacebookutils 使用了“FBSDKLoginManager”声明,让我们看看这是否有效。事实上,让我们将默认设置为“系统帐户”,...代码如下:

[[PFFacebookUtils facebookLoginManager] setLoginBehavior:FBSDKLoginBehaviorSystemAccount];

[PFFacebookUtils logInInBackgroundWithReadPermissions:FACEBOOK_READ_PERMISSIONS block:^(PFUser *user, NSError *error) {
}]; 

是的,这段代码可以编译,这段代码可以工作,只需确保在调用登录内容之前声明登录行为,最好在初始化代码库、解析、解析 Facebook 实用程序等时在 AppDelegate 中声明。 .

事实上,为了确保这对您有用,我刚刚下载了最新版本的 PARSE iOS SDK,它具有相同的功能。这是您的选项,它来自 Facebook SDK for iOS,它提供 PFFFacebookUtils:

@typedef FBSDKLoginBehavior enum

@abstract Passed to the \c FBSDKLoginManager to indicate how Facebook Login should be attempted.

@discussion Facebook Login authorizes the application to act on behalf of the user, using the user's Facebook account. Usually a Facebook Login will rely on an account maintained outside of the application, by the native Facebook application, the browser, or perhaps the device itself. This avoids the need for a user to enter their username and password directly, and provides the most secure and lowest friction way for a user to authorize the application to interact with Facebook.

The \c FBSDKLoginBehavior enum specifies which log in method should be attempted. Most applications will use the default, which attempts a login through the Facebook app and falls back to the browser if needed.

If log in cannot be completed using the specificed behavior, the completion handler will be invoked with an error in the \c FBSDKErrorDomain and a code of \c FBSDKLoginUnknownErrorCode. */

typedef NS_ENUM(NSUInteger, FBSDKLoginBehavior)
{
  /*!
   @abstract Attempts log in through the native Facebook app. If the Facebook app is
   not installed on the device, falls back to \c FBSDKLoginBehaviorBrowser. This is the
   default behavior.
   */
  FBSDKLoginBehaviorNative = 0,
  /*!
   @abstract Attempts log in through the Safari browser
   */
  FBSDKLoginBehaviorBrowser,
  /*!
   @abstract Attempts log in through the Facebook account currently signed in through Settings.
   If no Facebook account is signed in, falls back to \c FBSDKLoginBehaviorNative.
   */
  FBSDKLoginBehaviorSystemAccount,
  /*!
   @abstract Attemps log in through a modal \c UIWebView pop up

   @note This behavior is only available to certain types of apps. Please check the Facebook
   Platform Policy to verify your app meets the restrictions.
   */
  FBSDKLoginBehaviorWeb,
};

关于ios - PFFacebookUtils logInInBackgroundWithReadPermissions : block: opens Facebook app instead of using system account,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32033660/

相关文章:

iphone - 在构造函数中获取属性集

javascript - 保存成功不使用 parse.com 对象

javascript - 解析: How can you have full administrative privileges in code?

objective-c - Swift FB SDK - 无法构建模块/无法导入桥接头

ios - 如何将椭圆形图层绘制到 UITextField

ios - Metal sample 计数

ios - 如何在 iOS 中获取当前时间而不是设备时间

ios - 从 Parse 查询中访问 NSArray

iOS 9 Facebook 登录模拟器-canOpenURL : failed for URL: "fbauth2:///" - error: "(null)"

ios - "Error Domain Code=324"使用 Facebook 方法上传照片时