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!

4

1 回答 1

1

没有可用的解决方案。iOS 原生 facebook 应用程序不允许写入或保存帐户到ACAccountStore. 它只允许从ACAccountStore. iOS 一次只允许存储 1 个 facebook 帐户。尝试执行这些步骤,您将很容易理解这一点,

  1. 将 facebook 帐户添加到设置应用程序并尝试获得访问权限。它将获得盛大的许可。

  2. 删除帐户并尝试获取它将拒绝访问的权限。

  3. 添加一个 facebook 帐户并获得访问权限并尝试将新帐户保存到ACAccountStore,它会说 Native 应用程序不允许将帐户保存到ACAccountStore

建议的解决方案是,将帐户添加到设置应用程序并使用它登录,然后使用社交框架或presentOSIntegratedDialog.

于 2014-01-21T07:30:59.437 回答