ios - 我们什么时候使用saveAccount :(ACAccount *)account of ACAccountStore class?

标签 ios objective-c iphone facebook

请说明我们何时使用此方法? - (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/

相关文章:

ios - 界面生成器中的未知类

iphone - 滚动时如何使第一个和最后一个 UITableView 单元格留在屏幕上?

objective-c - si_user_byuid/getpwuid 中的内存泄漏源自 iOS 中的 CPSharedResourcesDirectory

iphone - 如何使用 NSXMLParser 解析多个 XML 标签

ios - 当不知道运行时的大小时提供正确的图像大小

ios - SpriteKit SKView 不再在 iOS 9 中的场景之间转换

ios - 如何使声音无效?

ios - swift 3 : Append to UITextField while Editing Changed

android - 在 WKWebView/UIWebView 中启用 WebRTC 支持

ios - 如何根据我的要求自定义 tableview 标题?