2011-11-04 3 views
3

사용자가 iOS 5에서 자신의 트위터 계정에 로그인 할 수있는 버튼을 추가하고 싶지만 트위터 핸들을 UITextField에 채우고 싶습니다. iPhone에 iOS 5가 실행되고 계정이 활성화되어 있는지 확인하는 코드가 있습니다. 핸들을 유지하려면 어떻게해야합니까?트위터에서 사용자 이름 유지 iOS5 iPhone

답변

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"]]; 
+0

당신의 valueForKey는 twitterHandle해야한다. – jrtc27

+0

@ jrtc27 감사합니다. –

+0

해당 코드에는 몇 가지 문제가 있지만 몇 가지 사항을 변경하면 훌륭하게 작동합니다 (예 : standDefaults = standardUserDefaults). – Eric

관련 문제