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.
ACAccountStore *store = [[ACAccountStore alloc] init];
ACAccountType *accountType = [store accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
NSArray *accounts = [store accountsWithAccountType:accountType];
NSLog(@"accounts:%@", accounts);
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.
Instead of using following:
NSArray *readPermissions = [[NSArray alloc] initWithObjects:@"email",@"friends_location",@"status_update",@"publish_actions",nil];
[FBSession openActiveSessionWithPublishPermissions:readPermissions defaultAudience:FBSessionDefaultAudienceEveryone allowLoginUI:YES completionHandler:^(FBSession *session, FBSessionState state, NSError *error) {
//Your code here for handling forward things;
}
Use this code:
NSArray *readPermissions = [[NSArray alloc] initWithObjects:@"email",@"friends_location",@"status_update",@"publish_actions",nil];
FBSession* sess = [[FBSession alloc] initWithPermissions:[NSArray arrayWithObject:readPermissions]];
[FBSession setActiveSession:sess];
[sess openWithBehavior:(FBSessionLoginBehaviorWithFallbackToWebView) completionHandler:^(FBSession *session, FBSessionState status, NSError *error) {
[self onSessionStateChange:session
andState:status
andError:error];
//Your code here for handling forward things;
}];
Based on everything I've read on Facebook's Developer sites (which is somewhat contradictory) the workflow of a "publish only" app is not something to which they've given much thought, and Apple/iOS seems to have disregarded altogether.
Facebook provides some guidance in the 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.
This is the route I am currently following. Slightly different, but same general effect.
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];
}];
The upshot is, the app will always bypass the IOS6 integration for signing on for publish, and in most cases (since users typically will already have Facebook installed on the phone) switchover to the Facebook app for a single auth approval.
If the user elects to sign-on to our app using their Facebook account, I call openActiveSessionWithReadPermissions
, which will use the IOS6 Facebook integration if present. If they subsequently decide to share, I then call reauthorizeWithPublishPermissions
which will also use the IOS6 integration if available.
Given the minimal and confusing documentation available I cannot be sure if this is the "right" way to approach this, but it seems to work. You can use the same code for an IOS5 or IOS6 app since it only makes calls through the Facebook SDK. It also honors the not mixing read/publish permissions in the same request Facebook is now promoting.
Sorry but for me in ios6 the line
ACAccountType* at = [as accountTypeWithAccountTypeIdentifier: @"com.apple.facebook"];
Does not return nil even if the user does not have an account configured...
Which means you can just check what is the ios version of the user (5 or 6)
NSString *currSysVer = [[UIDevice currentDevice] systemVersion];
This link can be helpful.