[英]Display detailed contact card if contact has more than 1 phone number
If a contact has only 1 phone number, I want to select it. 如果联系人只有一个电话号码,我想选择它。 If it has more than 1 phone number, then I want to display the detailed contact card.
如果它有超过1个电话号码,那么我想显示详细的联系卡。
I am using the below method, which works fine. 我使用下面的方法,工作正常。
- (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
}
}
}
Then, I implement this Utility method to display Detailed Contact card: 然后,我实现此实用程序方法以显示详细联系卡:
- (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);
}
}
but this method never gets called? 但这种方法永远不会被调用? If I comment out the first method, then the second method gets called.
如果我注释掉第一个方法,那么第二个方法就会被调用。 How can I call both, or is there another way to achieve this?
我怎么能同时打电话,还是有其他办法实现这一目标?
The solution is to do this is to add a predicate
before starting the peoplePicker
in this case it would be: 解决方法是在启动
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];
}
similarly in case of emailAdresses, replace : @"phoneNumbers.@count = 1"
with @"emailAddresses.@count = 1"
. 同样在emailAdresses的情况下,用
@"emailAddresses.@count = 1"
替换: @"phoneNumbers.@count = 1"
@"emailAddresses.@count = 1"
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.