首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用ACAccountStore保存Facebook帐户

使用ACAccountStore保存Facebook帐户
EN

Stack Overflow用户
提问于 2013-12-05 18:07:50
回答 1查看 2.6K关注 0票数 5

我正在尝试使用iOS Social.framework与Facebook共享。然而,大多数用户不会在Settings>Facebook中安装Facebook,因此当您打开UIActivityViewController时,Facebook就不会出现,它只是没有列出。(请看UIActivity with no settings for Facebook或谷歌"facebook在UIActivityViewController中没有显示“,有很多人试图解决这个问题。)

我们的应用程序已经使用了Facebook,所以我可以获得Facebook帐户的信息,所以我想我只需要得到信息,然后将信息保存在Settings>Facebook中。这是我的密码。(我是从)account of ACAccountStore class?iOS requestAccessToAccountsWithType is Not Showing Permission Prompt / NSAlert那里得到的)

代码语言:javascript
复制
- (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);
        }
    }];
}

我在那里添加了对requestAccessToAccountsWithType的调用,因为在没有saveAccount的情况下,我得到了一个ACErrorPermissionDenied。当我运行这个程序时,我确实看到我的应用程序在Facebook对话框中短暂地滑到一边(如果我在Facebook的网站上删除我的应用程序,它会弹出完整的对话框,询问我所授予的权限)。

问题是,授予总是不,所以我从来没有机会保存帐户。我在这里错过了什么?

我是在一个真正的设备上运行的,它安装和安装了Facebook。

我很感谢你在这方面的帮助,谢谢!

EN

回答 1

Stack Overflow用户

发布于 2014-01-21 07:30:59

没有解决办法可供使用。iOS本地facebook应用程序不允许向ACAccountStore写入或保存帐户。它只允许从ACAccountStore访问帐户。iOS一次只允许存储1个facebook帐户。试着做这些你会很容易理解的步骤,

  1. 将facebook帐户添加到“设置应用程序”中,并尝试获得访问它的权限。这将是大许可。
  2. 删除帐户并尝试获得它将拒绝访问的权限。
  3. 添加facebook帐户并获得访问权限,并尝试将新帐户保存到ACAccountStore,这将说明本机应用程序不允许将帐户保存到ACAccountStore

建议的解决方案是,将帐户添加到设置应用程序并与其登录,并使用社交框架( Social )或presentOSIntegratedDialog共享。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20407468

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档