我想点击添加一个按钮,允许用户在iOS 5中登录他们的Twitter帐户,但我希望他们的Twitter句柄填充到UITextField中。我有代码确保他们的iPhone运行iOS 5并且他们的帐户已启用。我如何保留他们的手柄?
答案 0 :(得分:4)
//get Twitter username and store it
ACAccountStore *accountStore = [[ACAccountStore alloc] init];
ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
[accountStore requestAccessToAccountsWithType:accountType withCompletionHandler:^(BOOL granted, NSError *error) {
if(granted) {
NSArray *accountsArray = [accountStore accountsWithAccountType:accountType];
ACAccount *twitterAccount = [accountsArray objectAtIndex:0];
;
[[NSUserDefaults standardUserDefaults] setValue:twitterAccount.username forKey:@"twitterHandle"];
}
//get the username later...
[textField setText:[[NSUserDefaults standardUserDefaults] valueForKey:@"twitterHandle"]];
答案 1 :(得分:0)