0

我正在尝试在通讯簿中获取联系人的名字,然后将其存储在数组中。但是我无法将联系人存储在数组中。这是我尝试过的。

 -(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

}
}
4

1 回答 1

1

完成......实际上需要初始化数组。

于 2013-09-01T08:38:59.507 回答