7

Is there a way to know with FACEBOOK SDK 3.1 and iOS 6 if the user has defined his facebook account in the iPhone settings for native facebook use?

What I want to do is when opening my app, if the user has defined a "native facebook account" in iPhone setting, immediately show the "allow/don't allow" iOS 6 alert. But I want to do it only for native integration. What I mean, is that if know I can just try an "openSession" with FBSession, and it will show it, but if user has not defined the native account, I don't want the app to go to Safari or the facebook app. So I want to try to connect only if user has defined an account.

anyone knows a way to know?

tkanzakic
  • 5,499
  • 16
  • 34
  • 41
Jack Kapow
  • 211
  • 4
  • 9
  • This has been answered here: http://stackoverflow.com/a/12811583/312312 – Lefteris Dec 18 '12 at 09:48
  • 1
    Hey first thanks allot!!! problem is it seems that it even if an account was configured or not ACAccountType* at = [as accountTypeWithAccountTypeIdentifier: @"com.apple.facebook"]; at does not seem to be nil in ios 6 – Jack Kapow Dec 18 '12 at 11:58

1 Answers1

2

This is working for me:

//Step 1. create and store an ACAccountStore in an ivar
ACAccountStore* as = [[ACAccountStore alloc] init];
self.accountStore = as;
[as release];

//Step 2. Get the facebook account type
//Do not use the constant if you are in iOS5, use this string:@"com.apple.facebook"
ACAccountType* at = [self.accountStore accountTypeWithAccountTypeIdentifier: @"com.apple.facebook"];

//Step 3. request access to the facebook account, passing your facebook app id
__block typeof(self) bself = self;
[self.accountStore requestAccessToAccountsWithType:at
                            options:@{(NSString *)ACFacebookAppIdKey: kFBAppId }
                         completion:^(BOOL granted, NSError *error)
 {
     //Step 4. Check if the account is integrated natively
     //Note: if granted is NO, check for the error to see what's going on.
     BOOL nativeAccount = granted == YES && [bself.accountStore accountsWithAccountType:at];


     //Step 5. clean the account store.
     bself.accountStore = nil;
 }];
Lio
  • 4,225
  • 4
  • 33
  • 40