5

I'm trying to use iOS Social.framework to share to Facebook. However, most users will not have Facebook setup in Settings>Facebook so therefore Facebook doesn't show up when you bring up a UIActivityViewController, it just isn't listed. (See UIActivity with no settings for Facebook or just google "facebook doesn't show in UIActivityViewController," there's plenty of people trying to solve this problem.)

Our app already uses the Facebook SDK so I can get at the Facebook account info, so I thought I would just get the info and then save the info in Settings>Facebook. Here's my code. (Which I got from When do we use saveAccount:(ACAccount *)account of ACAccountStore class? and iOS requestAccessToAccountsWithType is Not Showing Permission Prompt / NSAlert)

- (void)storeAccountWithAccessToken:(NSString *)token secret:(NSString *)secret {

    if (self.accountStore == nil) {
        self.accountStore = [[ACAccountStore alloc] init];
    }

    //We start creating an account by creating the credentials object
    ACAccountCredential *credential = [[ACAccountCredential alloc] initWithOAuthToken:token tokenSecret:secret];
    ACAccountType *acctType =[self.accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
    ACAccount *newAccount = [[ACAccount alloc] initWithAccountType:acctType];
    //Here we assign credentials and now can save account
    newAccount.credential = credential;

    NSDictionary *options = [[NSDictionary alloc] initWithObjectsAndKeys:
                             [VVEnvironment stringForKey:kVVEnvironmentKeyFacebookAppID], (NSString *)ACFacebookAppIdKey,
                             [NSArray arrayWithObject:@"basic_info"], (NSString *)ACFacebookPermissionsKey,
                             ACFacebookAudienceEveryone, (NSString *)ACFacebookAudienceKey,
                             nil];


    [_accountStore requestAccessToAccountsWithType:acctType options:options completion:^(BOOL granted, NSError *error) {
        if (granted == YES) {
            [self.accountStore saveAccount:newAccount withCompletionHandler:^(BOOL success, NSError *error) {

                if (success) {
                    NSLog(@"the account was saved!");
                }
                else {
                    if ([error code] == ACErrorPermissionDenied) {
                        NSLog(@"Got a ACErrorPermissionDenied, the account was not saved!");
                    }
                    NSLog(@"the account was not saved! %d, %@", [error code], error);
                }
            }];
        }
        else {
            NSLog(@"ERR: %@ ",error);
        }
    }];
}

I added the call to requestAccessToAccountsWithType there because without I was getting a ACErrorPermissionDenied back from saveAccount. When I run this I do see my app slide briefly aside for the Facebook dialog (if I delete my app on Facebook's website it does bring up the full dialog asking me for permissions which I grant.)

The problem is that granted is always NO, so I never get a chance to save the account. What am I missing here?

I am running this on a real device that has the Facebook App installed and setup.

I'd appreciate any help on this, thanks!

Community
  • 1
  • 1
Paul Cezanne
  • 8,629
  • 7
  • 59
  • 90
  • Did this 1 is solved?. and can you said about how you separated token and secret from `[FBSession activeSession] accessTokenData.accessToken]` Am also in the same situation.. – Rafeek Jan 09 '14 at 11:56
  • I was not able to solve this. – Paul Cezanne Jan 09 '14 at 15:49
  • Just wondering if you tried saveAccount before requestAccessTo... ? – theLastNightTrain Jul 26 '14 at 21:34
  • Yes, from the question: "I added the call to requestAccessToAccountsWithType there because without I was getting a ACErrorPermissionDenied back from saveAccount." – Paul Cezanne Jul 27 '14 at 14:22
  • So it seems that it works for Twitter (according to the question you reference) but not for Facebook. Very frustrating - ideally we wouldn't even have to use the FacebookSDK if we only want registration/login/sharing functionality I was hoping it would be possible just with the Social framework. – theLastNightTrain Aug 05 '14 at 20:50
  • Yes and no. There isn't a need to save an account for Twitter since the Twitter app saves it for you. So the common use case is already covered. And yes, just using Social would be ideal. – Paul Cezanne Aug 05 '14 at 21:05
  • Were you able to push through with this solution? – KarenAnne May 08 '15 at 07:14
  • No. I was not able to solve this (and I no longer work for that company.) – Paul Cezanne May 08 '15 at 09:56

1 Answers1

1

There is no solution available for this. iOS native facebook applications are not allowed to write or save account to ACAccountStore. It only allow to access account from the ACAccountStore. iOS only allow to store 1 facebook account at a time. Try to do these steps you will understand this easily,

  1. Add a facebook account to settings App and try to get permission to access it. It will grand permission.

  2. Remove account and try to get the permission it will deny access.

  3. Add a facebook account and get access and try to save new account to ACAccountStore, It will say that Native applications are not allowed to save account to ACAccountStore.

The proposed solution is, Add the account to settings App and login with it and Share using Social framework or presentOSIntegratedDialog.

Rafeek
  • 523
  • 3
  • 16
  • The proposed solution is not a solution for the app, but rather a behavior change for the user. – Paul Cezanne Jan 21 '14 at 12:04
  • 1
    Just down voting so it doesn't get the bounty. I'll upvote another one of your answers so you don't lose out on reputation points. – Paul Cezanne Aug 19 '14 at 00:40
  • @PaulCezanne: did you get any solution for saving facebook account to settings? – Rafeek Sep 03 '14 at 07:18
  • No, I did not find a solution. – Paul Cezanne Sep 03 '14 at 11:08
  • Does anybody know if this is also not possible in OSX? I get `com.apple.accounts Code=7 "The application is not permitted to access Facebook accounts"`. Tried disabling sandbox mode, same. – User Sep 23 '15 at 22:31