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.
The app requires the "publish_actions" permission from Facebook for the only thing it does with 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:
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.
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.
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.
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?
EDIT:
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.
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.
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: ...]
}
See Question&Answers more detail:
os