Recognize if user defined their own facebook account in iOS 6 settings

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

What I want to do is when I open my application, if the user has defined "native facebook account" in the iPhone settings, immediately show the "allow / not allow" iOS 6 warning. But I want to do this only for native integration. I mean, if I know that I can just try โ€œopenSessionโ€ with FBSession and it will show it, but if the user has not defined their own account, I donโ€™t want the application to go to Safari or the facebook application, so I want try connecting only if the user has defined an account.

Does anyone know a way to find out?

+7
source share
1 answer

This works 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 going on. BOOL nativeAccount = granted == YES && [bself.accountStore accountsWithAccountType:at]; //Step 5. clean the account store. bself.accountStore = nil; }]; 
+2
source

All Articles