我们何时使用ACAccountStore类的saveAccount:(ACAccount *)帐户? [英] When do we use saveAccount:(ACAccount *)account of ACAccountStore class?

查看:277
本文介绍了我们何时使用ACAccountStore类的saveAccount:(ACAccount *)帐户?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请问我何时使用这种方法?
- (void)saveAccount:(ACAccount *)account withCompletionHandler:(ACAccountStoreSaveCompletionHandler)completionHandler

Please clarify me when do we use this method ? - (void)saveAccount:(ACAccount *)account withCompletionHandler:(ACAccountStoreSaveCompletionHandler)completionHandler

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

As I know we get access to the account through OAuth and we do not get user's credentials. So how do we create an account? I've found that ACAccount has the only one creation method: - (id)initWithAccountType:(ACAccountType *)type What actually happens when we create account this way? And can we save it now ?

推荐答案

好的,最后我找到了有关它的信息。
考虑这种情况:
我们的应用程序已经被用户授权,我们同时拥有访问令牌和秘密。现在我们想要支持新的iOS 6功能并在设置中创建Twitter(例如)帐户。为此,我们需要将这些令牌迁移到中央帐户存储区。
以下是如何:

Ok, finally I've found the information about it. Consider this scenario: Our app have already been authorized by the user and we've got both access token and secret. Now we want to support new iOS 6 features and create twitter (for example) account in Settings. To do this we need to migrate these tokens to the central account store. Here's how:

- (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
        }
    }];
}

有关它的更多信息,请在此处阅读如何迁移令牌

For more information about it read here how to migrate tokens

这篇关于我们何时使用ACAccountStore类的saveAccount:(ACAccount *)帐户?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆