gpt4 book ai didi

ios - 使用 [FBSession openActiveSessionWithPublishPermissions : . 时出错。]

转载 作者:可可西里 更新时间:2023-11-01 03:38:48 25 4
gpt4 key购买 nike

我正在更新一个应用程序以使用最新的 Facebook SDK,以便获得对 iOS6 原生 Facebook 支持的访问权。它目前使用相当旧的 Facebook SDK 版本。

该应用程序需要 Facebook 的“publish_actions”许可才能与 Facebook 进行唯一的操作。

我最初认为我可以使用 [FBSession openActiveSessionWithPublishPermissions: ...] 但是当用户在 iOS6 设置中配置了 Facebook 时,这在 iOS6 上失败了。由于此要求,它失败了,from the Facebook docs :

Note, to use iOS 6 native auth, apps need change the way they request permissions from users - apps must separate their requests for read and write permissions. The Facebook SDK for iOS supports these features and helps developers use them to build apps that work on multiple iOS versions and device configurations.

这是一个很大的 PITA,IMO。我们的偏好是提示用户一次获得许可并完成它,但 Apple/Facebook 的"new"理想是在需要但尚未授予时在上下文中提示特定权限。

目前的计划是为没有在“设置”中配置 Facebook 的 iOS5 用户和 iOS6 用户保留我们的旧行为。并符合使用 native-access 的 iOS6 用户的新双提示。

问题是,执行此操作的最佳方法是什么?我应该如何检测 Facebook SDK 是否会选择 iOS6 native 登录与回退机制?我是否忽略了一些明显的东西?

编辑:

gerraldWilliam 让我走上了正确的轨道。他的解决方案几乎可以工作,但 ACAccountTypeIdentifierFacebook 在 iOS5 中不可用。此外,如果用户在“设置”中阻止 FB 访问应用程序,则 accountsWithAccountType 调用将返回一个空数组。

可以通过请求帐户类型匹配标识符“com.apple.facebook”来解决第一个问题——这将在 iOS5 上返回 nil,在 iOS6 上返回一个真实的帐户类型对象。

但是第二个问题无解。我的新计划是始终以只读权限打开 iOS6 上的初始 session ,并在需要时在上下文中提示发布权限。在 iOS5 上,我仍然会打开初始 session ,指定所需的 publish_actions 权限。这是代码:

ACAccountStore* as = [[ACAccountStore new] autorelease]; 
ACAccountType* at = [as accountTypeWithAccountTypeIdentifier: @"com.apple.facebook"];
if ( at != nil ) {
// iOS6+, call [FBSession openActiveSessionWithReadPermissions: ...]

} else {
// iOS5, call [FBSession openActiveSessionWithPublishPermissions: ...]
}

最佳答案

基于我在 Facebook 的开发者网站上阅读的所有内容(这有点矛盾)“仅发布”应用程序的工作流程并不是他们考虑太多的东西,Apple/iOS 似乎完全忽视了.

Facebook 在 docs you referenced 中提供了一些指导:

Tip 5: Disabling the native Login Dialog

In some cases, apps may choose to disable the native Login Dialog to use new versions of the Facebook SDK but to avoid rewriting the ways they request permissions from users. To use the previous behavior of fast-app-switch for login, use the deprecated FBSession methods openActiveSessionWithPermissions and reauthorizeWithPermissions.

这是我目前正在走的路线。略有不同,但总体效果相同。

if (FBSession.activeSession.isOpen  == NO) {
// This will bypass the ios6 integration since it does not allow for a session to be opened
// with publish only permissions!
FBSession* sess = [[FBSession alloc] initWithPermissions:[NSArray arrayWithObject:@"publish_actions"]];
[FBSession setActiveSession:sess];
[sess openWithBehavior:(FBSessionLoginBehaviorWithFallbackToWebView) completionHandler:^(FBSession *session, FBSessionState status, NSError *error) {
[self onSessionStateChange:session
andState:status
andError:error];
}];

结果是,该应用程序将始终绕过 IOS6 集成以进行发布登录,并且在大多数情况下(因为用户通常已经在手机上安装了 Facebook)切换到 Facebook 应用程序以获得单一授权批准。

如果用户选择使用他们的 Facebook 帐户登录我们的应用程序,我将调用 openActiveSessionWithReadPermissions,它将使用 IOS6 Facebook 集成(如果存在)。如果他们随后决定共享,我将调用 reauthorizeWithPublishPermissions,如果可用,它也将使用 IOS6 集成。

鉴于可用的文档最少且令人困惑,我无法确定这是否是处理此问题的“正确”方法,但它似乎有效。您可以对 IOS5 或 IOS6 应用程序使用相同的代码,因为它仅通过 Facebook SDK 进行调用。它还尊重 Facebook 现在正在推广的同一请求中不混合读取/发布权限。

关于ios - 使用 [FBSession openActiveSessionWithPublishPermissions : . 时出错。],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12810353/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com