我想从通讯录联系人中删除特定的电话号码。
它“似乎”起作用,因为它返回 true,但事实并非如此。
拜托,有人可以帮我吗?这太棒了!
ABAddressBookRef ab = ABAddressBookCreate();
ABRecordRef record = ABAddressBookGetPersonWithRecordID(ab,[myID intValue]);
NSError *error = NULL;
ABMultiValueRef phoneNumbers = ABRecordCopyValue(record,kABPersonPhoneProperty);
for(CFIndex i=0; i < ABMultiValueGetCount(phoneNumbers); i++){
NSString *phoneNumber = (NSString *)ABMultiValueCopyValueAtIndex(phoneNumbers,i);
//ckDebug(@"phoneNumber = %@", phoneNumber);
if ([[oDict objectForKey:@"value"] isEqualToString:phoneNumber]) {
BOOL didRemove = ABMultiValueRemoveValueAndLabelAtIndex(ABMultiValueCreateMutableCopy(phoneNumbers),i);
ckDebug(@"didRemove = %@\n", (didRemove ? @"TRUE" : @"FALSE"));
//and save it!
BOOL didSave = ABAddressBookSave(ab, (CFErrorRef *) error);
ckDebug(@"didSave = %@\n", (didSave ? @"TRUE" : @"FALSE"));
if (error) {
ckDebug(@"ABAddressBookSaveError = %@", error);
}
}
[phoneNumber release];
}
CFRelease(ab);