[英]Display contact properties if it has more than one phone number with ios8
[英]Display detailed contact card if contact has more than 1 phone number
如果聯系人只有一個電話號碼,我想選擇它。 如果它有超過1個電話號碼,那么我想顯示詳細的聯系卡。
我使用下面的方法,工作正常。
- (void)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker didSelectPerson:(ABRecordRef)person {
if (person != nil) {
ABMultiValueRef phoneNumbers = ABRecordCopyValue(person, kABPersonPhoneProperty);
if (ABMultiValueGetCount(phoneNumbers) == 1) {
//Do stuff to select phone number
}
}
}
然后,我實現此實用程序方法以顯示詳細聯系卡:
- (void)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker didSelectPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier {
NSString* phone = nil;
ABMultiValueRef phoneNumbers = ABRecordCopyValue(person, kABPersonPhoneProperty);
if (ABMultiValueGetCount(phoneNumbers) > 0) {
CFIndex index = ABMultiValueGetIndexForIdentifier(phoneNumbers, identifier);
phone = (__bridge_transfer NSString*)ABMultiValueCopyValueAtIndex(phoneNumbers, index);
}
}
但這種方法永遠不會被調用? 如果我注釋掉第一個方法,那么第二個方法就會被調用。 我怎么能同時打電話,還是有其他辦法實現這一目標?
解決方法是在啟動peoplePicker
之前添加一個predicate
,在這種情況下它將是:
-(void)getContacts {
ABPeoplePickerNavigationController *peoplePicker = [[ABPeoplePickerNavigationController alloc] init];
peoplePicker.peoplePickerDelegate = self;
if ([peoplePicker respondsToSelector:@selector(setPredicateForSelectionOfPerson:)])
{
// The people picker will select a person that has exactly one phone number and call peoplePickerNavigationController:didSelectPerson:,
// otherwise the people picker will present an ABPersonViewController for the user to pick one of the Phone Numbers.
peoplePicker.predicateForSelectionOfPerson = [NSPredicate predicateWithFormat:@"phoneNumbers.@count = 1"];
}
[self presentViewController:peoplePicker animated:NO completion:nil];
}
同樣在emailAdresses的情況下,用@"emailAddresses.@count = 1"
替換: @"phoneNumbers.@count = 1"
@"emailAddresses.@count = 1"
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.