2013-09-01 2 views
0

주소록에서 연락처의 첫 번째 이름을 가져온 다음 배열에 저장하려고합니다. 연락처에 연락처를 저장할 수 없습니다. 이것은 내가 시도한 것이다.AddressBook에서 연락처를 가져 와서 iOS 6에 배열로 저장하는 방법은 무엇입니까?

-(void)fetchAddressBook 
{ 
    ABAddressBookRef UsersAddressBook = ABAddressBookCreateWithOptions(NULL, NULL); 

    //contains details for all the contacts 
    CFArrayRef ContactInfoArray = ABAddressBookCopyArrayOfAllPeople(UsersAddressBook); 

    //get the total number of count of the users contact 
    CFIndex numberofPeople = CFArrayGetCount(ContactInfoArray); 

    //iterate through each record and add the value in the array 
    for (int i =0; i<numberofPeople; i++) { 
    ABRecordRef ref = CFArrayGetValueAtIndex(ContactInfoArray, i); 
    ABMultiValueRef names = (__bridge ABMultiValueRef)((__bridge NSString*)ABRecordCopyValue(ref, kABPersonFirstNameProperty)); 

    NSLog(@"name from address book = %@",names); // works fine. 

    NSString *contactName = (__bridge NSString *)(names); 
    [self.reterivedNamesMutableArray addObject:contactName]; 
    NSLog(@"array content = %@", [self.reterivedNamesMutableArray lastObject]);//shows null 

} 
} 

답변

1

완료 .... 실제로 배열을 초기화해야했습니다.