[英]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.