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