住所フィールドを持つ連絡先のみを表示したい.私はこのコードを使用しています..助けてください..
- (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 ストリート インド、TEST3 95-95684-956 NIL、TEST3 20-95684-956 NIL、
今、私はこの出力を得ています:
テスト1 テスト2 テスト2 テスト2
助けてください...重複が表示されます..