0
提取整个地址簿这是我的代码:从ABpeson目标C iPhone
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] [email protected]"%@:%@",compositeName,phone];
[compositeName release];
[_allItems addObject:field];
for (NSString *txt in _allItems)
{
contacts.text = [contacts.text stringByAppendingFormat:@"%@\n",txt];
}
}
[phones release];
}
CFRelease(_addressBookRef);
[allPeople release];
allPeople = nil;
}
我基本上要转储整个地址簿到一个UITextView称为contacts.text和刚才的名字和这样的名称编号:NUMBER分离:。我目前得到一个错误就行了
NSString* field = [NSString [email protected]"%@:%@",compositeName,phone];
任何帮助将是真棒:d
感谢 梅森
“错误”?什么错误? – 2010-07-21 19:33:11
/Users/hobbypunk/Desktop/Copy Whole Address Book/Classes/MainViewController.m:80:0/Users/hobbypunk/Desktop/Copy Whole Address Book/Classes/MainViewController.m:80:error:expected':'before' ]'令牌 – user393273 2010-07-21 19:36:11