Сохранить имя пользователя в Twitter iOS5 iPhone - PullRequest
3 голосов
/ 04 ноября 2011

Я хочу нажать кнопку «Добавить», которая позволяет пользователю войти в свою учетную запись Twitter в iOS 5, но я хочу, чтобы его дескриптор твиттера попал в UITextField.У меня есть код, чтобы убедиться, что их iPhone работает под управлением iOS 5 и их учетная запись включена.Как мне сохранить их ручку?

Ответы [ 2 ]

4 голосов
/ 04 ноября 2011
    //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"]];
0 голосов
/ 04 ноября 2011

Вы можете получить их дескриптор из объекта ACAccount и сохранить его по умолчанию или в другом месте.

http://developer.apple.com/library/ios/DOCUMENTATION/Accounts/Reference/ACAccountClassRef/Reference/Reference.html#//apple_ref/doc/uid/TP40011019-CH1-DontLinkElementID_5

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...