请说明我们何时使用此方法?
- (void)saveAccount:(ACAccount *)account withCompletionHandler:(ACAccountStoreSaveCompletionHandler)completionHandler
据我所知,我们可以通过 OAuth 访问帐户,但不会获得用户的凭据。那么我们如何创建一个帐户呢?我发现 ACAccount 只有一种创建方法:
- (id)initWithAccountType:(ACAccountType *)type
当我们以这种方式创建帐户时实际发生了什么?我们现在可以保存它吗?
最佳答案
好的,我终于找到了有关它的信息。 考虑这种情况: 我们的应用程序已经获得用户授权,我们已经获得了访问 token 和 secret 。现在我们要支持新的 iOS 6 功能并在设置中创建 twitter(例如)帐户。为此,我们需要将这些 token 迁移到中央帐户存储区。 方法如下:
- (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
关于ios - 我们什么时候使用saveAccount :(ACAccount *)account of ACAccountStore class?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13492580/