Recognize if user has defined a native facebook account in iOS 6 settings

非 Y 不嫁゛ 提交于 2019-12-05 05:24:44

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;
 }];
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!