这是我的代码:
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];
for ( NSString *txt in _allItems )
{
contacts.text = [contacts.text stringByAppendingFormat:@"%@\n",txt];
}
}
[phones release];
}
CFRelease(_addressBookRef);
[allPeople release];
allPeople = nil;
}
我基本上想要将整个地址簿转储到名为contacts.text的UItextView中,并且只有名称和数字,例如:NAME:NUMBER分隔:。我目前在线上出现错误
NSString* field = [NSString stringWithFormat@"%@:%@",compositeName,phone];
任何帮助都会很棒:D
由于 梅森
答案 0 :(得分:0)
NSString* field = [NSString stringWithFormat@"%@:%@",compositeName,phone];
应该是
NSString* field = [NSString stringWithFormat:@"%@:%@",compositeName,phone];