使用[FBSession openActiveSessionWithPublishPermissions:..]时出错 [英] Error when using [FBSession openActiveSessionWithPublishPermissions: ..]

查看:71
本文介绍了使用[FBSession openActiveSessionWithPublishPermissions:..]时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm updating an app to use the latest Facebook SDK in order to gain access to the iOS6 native Facebook support. It currently uses a pretty old version of the Facebook SDK.

该应用程序需要Facebook的publish_actions权限才能与Facebook进行唯一的操作。

The app requires the "publish_actions" permission from Facebook for the only thing it does with Facebook.

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

I initially thought I could use [FBSession openActiveSessionWithPublishPermissions: ...] but this fails on iOS6 when the user has Facebook configured in iOS6 settings. It fails because of this requirement, from the Facebook docs:


注意,要使用iOS 6原生身份验证,应用程序需要更改用户请求
权限的方式 - 应用必须将其请求分开读取
并写入权限。适用于iOS的Facebook SDK支持这些
功能,并帮助开发人员使用它们构建适用于
多个iOS版本和设备配置的应用程序。

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的新理想是在需要但尚未授予时在上下文中提示特定权限。

This is a big PITA, IMO. Our preference would be to prompt the user once for permission and be done with it, but the "new" ideal per Apple/Facebook is to prompt for specific permissions in-context when they're needed but not yet granted.

目前的计划是保留iOS5用户和未在设置中配置Facebook的iOS6用户的旧行为。并且符合使用原生访问的iOS6用户的新双提示。

The plan at the moment is to retain our old behavior for iOS5 users and iOS6 users who don't have Facebook configured in Settings. And conform to the new double-prompt for iOS6 users who are using native-access.

问题是,最好的方法是什么?如何检测Facebook SDK是否会选择iOS6本机登录与后备机制?我忽略了一些明显的东西吗?

The question is, what's the best way to do this? How should I go about detecting if the Facebook SDK will select the iOS6 native login vs the fallback mechanisms? Am I overlooking something obvious?

编辑:

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

gerraldWilliam put me onto the right track. His solution would almost work except that ACAccountTypeIdentifierFacebook isn't available in iOS5. Also that if the user blocks FB access in Settings to the app then the accountsWithAccountType call will return an empty array.

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

It's possible to get around the first problem by asking for the account type matching identifier "com.apple.facebook" - this will return nil on iOS5, and a real account type object on iOS6.

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

But the second problem is unsolvable. My new plan is to always open the initial session on iOS6 with read-only permissions and prompt later, in context, for publish permission if required. On iOS5 I'll still open the initial session specifying the desired publish_actions permission. Here's the code:

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

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


推荐答案

ACAccountStore *store = [[ACAccountStore alloc] init];

ACAccountType *accountType  = [store accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
NSArray *accounts = [store accountsWithAccountType:accountType];
NSLog(@"accounts:%@", accounts);

如果账户为零(或者它可能返回一个空数组,我不确定),那么用户尚未在iOS6中配置Facebook。您可以测试该值,如果该值表明尚未为iOS6配置Facebook,则可以调用您的回退机制。

if accounts is nil (or maybe it returns an empty array, I'm not sure), then the user has not configured Facebook in iOS6. You can test for that and if the value indicates that Facebook has not been configured for iOS6, you can call your fallback mechanism.

这篇关于使用[FBSession openActiveSessionWithPublishPermissions:..]时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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