请告诉我什么时候用这个方法?- (void)saveAccount:(ACAccount *)account withCompletionHandler:(ACAccountStoreSaveCompletionHandler)completionHandler
据我所知,我们通过OAuth访问该帐户,但没有获得用户的凭据。那么我们如何创建一个帐户呢?我发现ACAccount只有一种创建方法:- (id)initWithAccountType:(ACAccountType *)type,当我们以这种方式创建account时会发生什么?我们现在可以保存它吗?
发布于 2012-11-26 22:19:10
好了,我终于找到关于它的信息了。考虑这样的场景:我们的应用程序已经得到了用户的授权,并且我们同时获得了访问令牌和密钥。现在我们想要支持iOS 6的新功能,并在设置中创建推特(例如)帐户。为此,我们需要将这些令牌迁移到中央帐户存储。下面是操作步骤:
- (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
https://stackoverflow.com/questions/13492580
复制相似问题