我想要爲iPhone地址簿中存儲的聯繫人獲取帶有「iPhone」,「家庭電話」,「手機號碼」,「其他號碼」等差異標籤的所有電話號碼。如何獲取地址簿中所有聯繫人的所有電話號碼和標籤?
我該如何得到它?
請幫忙。
在此先感謝。
我想:這是崩潰
ABAddressBookRef ab=ABAddressBookCreate();
CFArrayRef people = ABAddressBookCopyArrayOfAllPeople(ab);
NSMutableArray *allNumbers = [[NSMutableArray alloc] initWithCapacity:CFArrayGetCount(people)];
for (CFIndex i = 0; i < CFArrayGetCount(people); i++) {
ABRecordRef person = CFArrayGetValueAtIndex(people, i);
ABMultiValueRef numbers = ABRecordCopyValue(person, kABPersonPhoneProperty);
for (CFIndex j=0; j < ABMultiValueGetCount(numbers); j++) {
CFStringRef locLabel = ABMultiValueCopyLabelAtIndex(numbers, i);
NSString *phoneLabel =(NSString*) ABAddressBookCopyLocalizedLabel(locLabel);
CFStringRef phoneNumberRef = ABMultiValueCopyValueAtIndex(numbers, j);
CFStringRef locLabel1 = ABMultiValueCopyLabelAtIndex(numbers, j);
NSString *phoneLabel1 =(NSString*) ABAddressBookCopyLocalizedLabel(locLabel);
NSLog(@" ####### phone no -> %@ , phone label -> %@ #######)", locLabel1, phoneLabel1);
//CFRelease(phones);
NSString *phoneNumber = (NSString *)phoneNumberRef;
CFRelease(phoneNumberRef);
CFRelease(locLabel);
NSLog(@"phone no -> %@ , phone label -> %@)", phoneNumber, phoneLabel);
[phoneNumber release];
}
CFRelease(numbers);
}
CFRelease(people);
是不是有'CFRelease(電話);'後失蹤的for循環? – newenglander
「ABMultiValueRef *手機」應更改爲「ABMultiValueRef手機」 – glishijie