I am using the following code (showed on WWDC 2012 videos):
self.accountStore = [[ACAccountStore alloc] init];
ACAccountType *facebookAccountType = [self.accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
[self.accountStore requestAccessToAccountsWithType:facebookAccountType
withCompletionHandler:^(BOOL granted, NSError *e) {
if (granted)
{
NSArray *accounts = [self.accountStore
accountsWithAccountType:facebookAccountType];
self.facebookAccount = [accounts lastObject];
} else {
// Fail gracefully...
}
}];
I have also added the NSDictionary
to my .plist
file:
So, my problem is that I am receiving the following exception:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Access options are required for this account type.'
I have tried with this ACAccountTypeIdentifierTwitter
and ACAccountTypeIdentifierSinaWeibo
. I am not receiving any exception although they are always returning granted == NO
Well, the WWDC 2012 shows one thing, but the documentation shows another... The method they are using is now deprecated:
– requestAccessToAccountsWithType:withCompletionHandler: Deprecated in iOS 6.0
What you should do:
ACAccountType *facebookAccountType = [self.accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
NSDictionary *options = @{
@"ACFacebookAppIdKey" : @"123456789",
@"ACFacebookPermissionsKey" : @[@"publish_stream"],
@"ACFacebookAudienceKey" : ACFacebookAudienceEveryone}; // Needed only when write permissions are requested
[self.accountStore requestAccessToAccountsWithType:facebookAccountType options:options
completion:^(BOOL granted, NSError *error) {
if (granted)
{
NSArray *accounts = [self.accountStore
accountsWithAccountType:facebookAccountType];
self.facebookAccount = [accounts lastObject];
} else {
NSLog(@"%@",error);
// Fail gracefully...
}
}];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With