使用ACAccountStore保存Facebook帐户

 瓜子HR刘冲 发布于 2023-02-12 16:32

我正在尝试使用iOS Social.framework分享到Facebook.但是,大多数用户不会在设置> Facebook中设置Facebook,因此当您调出UIActivityViewController时Facebook不会显示,但它没有列出.(参见UIActivity没有设置Facebook或只是谷歌"Facebook没有在UIActivityViewController中显示,"有很多人试图解决这个问题.)

我们的应用程序已经使用Facebook SDK,因此我可以获取Facebook帐户信息,所以我想我会获取信息,然后将信息保存在设置> Facebook中.这是我的代码.(这是我从拿到我们什么时候使用saveAccount:(ACAccount*)帐户ACAccountStore类和iOS的requestAccessToAccountsWithType没有显示权限提示/ 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);
        }
    }];
}

我在那里添加了对requestAccessToAccountsWithType的调用,因为我没有从saveAccount获得ACErrorPermissionDenied.当我运行这个时,我确实看到我的应用程序幻灯片暂时放在Facebook对话框中(如果我在Facebook的网站上删除我的应用程序,它确实会显示完整对话框,询问我授予的权限.)

问题是授予永远是NO,所以我永远不会有机会保存帐户.我在这里错过了什么?

我在安装了Facebook App的真实设备上运行此设置.

我很感激任何帮助,谢谢!

撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有