[英]Extract entire addressbook name & number from ABperson objective c iphone
I need to know how to extract everyname & number from the address book in xcode for the iphone. 我需要知道如何从iPhone的xcode通讯录中提取每个姓名和电话号码。 I need to have the name and number in the following format: 我需要使用以下格式的名称和号码:
John Doe:000000000000000 Jane Doe:000000000000000 约翰·杜伊:000000000000000简·杜伊:000000000000000
Are you searching for all phone numbers of all people in the address book? 您是否要在通讯录中搜索所有人的所有电话号码? Look at ABAddressBookCopyArrayOfAllPeople . 查看ABAddressBookCopyArrayOfAllPeople 。
You could use it like this: (untested coded in browser) 您可以这样使用它:(未经浏览器编码在浏览器中)
ABAddressBookRef _addressBookRef = ABAddressBookCreate ();
NSArray* allPeople = (NSArray *)ABAddressBookCopyArrayOfAllPeople(_addressBookRef);
NSMutableArray* _allItems = [[NSMutableArray alloc] initWithCapacity:[allPeople count]]; // capacity is only a rough guess, but better than nothing
for (id record in allPeople) {
CFTypeRef phoneProperty = ABRecordCopyValue((ABRecordRef)record, kABPersonPhoneProperty);
NSArray *phones = (NSArray *)ABMultiValueCopyArrayOfAllValues(phoneProperty);
CFRelease(phoneProperty);
for (NSString *phone in phones) {
NSString* compositeName = (NSString *)ABRecordCopyCompositeName((ABRecordRef)record);
NSString* field = [NSString stringWithFormat@"%@:%@",compositeName,phone];
[compositeName release];
[_allItems addObject:field];
}
[phoness release];
}
CFRelease(_addressBookRef);
[allPeople release];
allPeople = nil;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.