2
我想顯示一個模式的ABAddressBook只有註冊了電子郵件的聯繫人。我如何實現這一目標?彈出ABAddressBook模式只有電子郵件聯繫人
我試過這段代碼:
- (IBAction)getContact {
// creating the picker
ABPeoplePickerNavigationController *picker = [[ABPeoplePickerNavigationController alloc] init];
ABAddressBookRef addressBook = ABAddressBookCreate();
CFArrayRef allPeople = ABAddressBookCopyArrayOfAllPeople(addressBook);
CFIndex nPeople = ABAddressBookGetPersonCount(addressBook);
for(CFIndex emailIndex = 0; emailIndex < nPeople; emailIndex++) {
ABRecordRef person = CFArrayGetValueAtIndex(allPeople, emailIndex);
ABMutableMultiValueRef emailRef= ABRecordCopyValue(person, kABPersonEmailProperty);
int emailCount = ABMultiValueGetCount(emailRef);
if(!emailCount) {
CFErrorRef error = nil;
ABAddressBookRemoveRecord(addressBook, person, &error);
if (error) NSLog(@"Error: %@", error);
}
}
picker.addressBook = addressBook;
picker.peoplePickerDelegate = self;
[self presentModalViewController:picker animated:YES];
}
的列表顯示了我所有的接觸,但「刪除」那些看起來像「NO NAME」,並且有一個名字的人,有一個真實的電子郵件。
非常感謝你:) –