首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >什么时候使用ACAccountStore类的saveAccount:(ACAccount *)account?

什么时候使用ACAccountStore类的saveAccount:(ACAccount *)account?
EN

Stack Overflow用户
提问于 2012-11-21 19:46:18
回答 1查看 2.3K关注 0票数 7

请告诉我什么时候用这个方法?- (void)saveAccount:(ACAccount *)account withCompletionHandler:(ACAccountStoreSaveCompletionHandler)completionHandler

据我所知,我们通过OAuth访问该帐户,但没有获得用户的凭据。那么我们如何创建一个帐户呢?我发现ACAccount只有一种创建方法:- (id)initWithAccountType:(ACAccountType *)type,当我们以这种方式创建account时会发生什么?我们现在可以保存它吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-11-26 22:19:10

好了,我终于找到关于它的信息了。考虑这样的场景:我们的应用程序已经得到了用户的授权,并且我们同时获得了访问令牌和密钥。现在我们想要支持iOS 6的新功能,并在设置中创建推特(例如)帐户。为此,我们需要将这些令牌迁移到中央帐户存储。下面是操作步骤:

代码语言:javascript
复制
- (void)storeAccountWithAccessToken:(NSString *)token secret:(NSString *)secret {
    //We start creating an account by creating the credentials object
    ACAccountCredential *credential = [[ACAccountCredential alloc] initWithOAuthToken:token tokenSecret:secret];
    ACAccountType *twitterAcctType =[self.accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
    ACAccount *newAccount = [[ACAccount alloc] initWithAccountType:twitterAcctType];
    //Here we assign credentials and now can save account
    newAccount.credential = credential;

    [self.accountStore saveAccount:newAccount withCompletionHandler:^(BOOL success, NSError *error) {

        if (success) {
            NSLog(@"the account was saved!");
        }
        else {
            //Handle error here
        }
    }];
}

有关它的更多信息,请阅读此处how to migrate tokens

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

https://stackoverflow.com/questions/13492580

复制
相关文章

相似问题

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