gpt4 book ai didi

ios - 如何在 iOS 6 中从 AddressBook 中获取联系人并将其存储在数组中?

转载 作者:行者123 更新时间:2023-11-29 03:40:12 24 4
gpt4 key购买 nike

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

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

}
}

最佳答案

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

关于ios - 如何在 iOS 6 中从 AddressBook 中获取联系人并将其存储在数组中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18556640/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com