我只想显示那些具有地址字段的联系人。我正在使用此代码..请帮助..
- (ABAddressBookRef)getValidAddress{
ABAddressBookRef allPeople = ABAddressBookCreate();
ABAddressBookRef contactsWithAddress = ABAddressBookCreate();
CFArrayRef allContacts = ABAddressBookCopyArrayOfAllPeople(allPeople);
CFIndex numberOfContacts = ABAddressBookGetPersonCount(allPeople);
CFErrorRef anError = NULL;
for(int i=0; i<numberOfContacts;i++){
ABRecordRef aPerson = CFArrayGetValueAtIndex(allContacts, i);
ABMultiValueRef AddressProperty = ABRecordCopyValue(aPerson, kABPersonAddressProperty);
if(ABMultiValueGetCount(AddressProperty)>0){
NSLog(@"this dude has address, he's on the list");
//ABAddressBookAddRecord(contactsWithEmail, aPerson, &anError);
}
else{
NSLog(@"this guy has no address, removing them from the addressBook");
ABAddressBookRemoveRecord(contactsWithAddress, aPerson, &anError);
}
}
return contactsWithAddress;
}
- (void)searchBarBookmarkButtonClicked:(UISearchBar *)searchBar
{
ABPeoplePickerNavigationController *picker = [[ABPeoplePickerNavigationController alloc] init];
ABAddressBookRef test = [self getValidAddress];
[picker setAddressBook:test];
NSArray* emailProp = [NSArray arrayWithObjects:
[NSNumber numberWithInt:kABPersonPhoneProperty],
[NSNumber numberWithInt:kABPersonEmailProperty],
[NSNumber numberWithInt:kABPersonBirthdayProperty],
[NSNumber numberWithInt:kABPersonAddressProperty],
nil];;
picker.displayedProperties = emailProp;
picker.peoplePickerDelegate = self;
[self presentModalViewController:picker animated:YES];
//[parentController presentModalViewController:picker animated:YES];
[picker release];
}
现在它在选择器中显示有地址的联系人,但现在我的输出是:
TEST1 44-541541-52 D-551,纽约,TEST2 54-965684-85 jV street India,TEST3 95-95684-956 NIL,TEST3 20-95684-956 NIL,
现在我得到这个输出:
测试1 测试2 测试2 测试2
请帮助...它显示重复..