The problem is that I always get runtime crashes at any method invoked at phones
variable.
At this version I get an error at 1
(ABMultiValueCopyValueAtIndex
).
If I'll comment this line, the code crashes at 2
(ABMultiValueGetCount
).
It looks like the property was empty. If I NSLog
the phones
variable. I get (null)
.
I test the code on iPhone Simulator, I have some dummy contacts there with some phone numbers.
Also firstName
and lastName
work like a charm.
for(id person in people){
NSString *firstName = (NSString *)ABRecordCopyValue(person, kABPersonFirstNameProperty);
NSString *lastName = (NSString *)ABRecordCopyValue(person, kABPersonLastNameProperty);
ABMultiValueRef phones = ABRecordCopyValue(person, kABPersonPhoneProperty);
NSString *phone = (NSString*)ABMultiValueCopyValueAtIndex(phones, 0); /*1*/
/*2/ id ph, phLb;
for (CFIndex i = 0; i < ABMultiValueGetCount(phones); i++) {
phLb = ABMultiValueCopyLabelAtIndex(phones, i);
ph = ABMultiValueCopyValueAtIndex(phones, i);
NSLog(@"%@,%@", phLb, ph);
CFRelease(phLb);
CFRelease(ph);
}
*/
NSLog(@"%@", firstName);
NSLog(@"%@", lastName);
NSLog(@"%@", phones);
NSLog(@"%@", phone);
[firstName release];
[lastName release];
[phone release];
[phones release];
}