简体   繁体   English

如果联系人属性与ios8有多个电话号码,则显示联系人属性

[英]Display contact properties if it has more than one phone number with ios8

In ios8, I would like to access contact properties if he has more than one numberphone but I don't know how to do it in iOS8. 在ios8中,我想访问联系人属性,如果他有多个号码电话,但我不知道如何在iOS8中这样做。

Here is my code in iOS7 : 这是我在iOS7中的代码:

-(BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person{

    //If person has just one phone number
    ABMultiValueRef phonesRef = ABRecordCopyValue(person, kABPersonPhoneProperty);
    if(ABMultiValueGetCount(phonesRef) == 1){

        CPIContact* contact = [self getCPIContactFromPerson:person andPhoneIndex:0];
        [self addContact:contact];

        // Dismiss the address book view controller.
        [_addressBookController dismissViewControllerAnimated:YES completion:nil];
        return NO;

    }else if(ABMultiValueGetCount(phonesRef) == 0){

        [[[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Common_information",nil) message:NSLocalizedString(@"EditCallSMS_noNumber", nil) delegate:nil cancelButtonTitle:NSLocalizedString(@"Common_ok",nil) otherButtonTitles:nil] show];

        return NO;
    }
    else{
        return YES;
    }

}

I know I have to use the method didSelectPerson from iOS8 but I don't know how to tell the app that it can continue after selecting a person like in iOS7. 我知道我必须使用iOS8中的didSelectPerson方法,但我不知道如何告诉应用程序在选择像iOS7这样的人之后可以继续。

I read about predicateForSelectionOfPerson on apple documentation but I don't understand how to use it. 我在Apple文档中读到了关于predicateForSelectionOfPerson但我不明白如何使用它。

https://developer.apple.com/library/ios/documentation/AddressBookUI/Reference/ABPeoplePickerNavigationController_Class/index.html#//apple_ref/occ/instp/ABPeoplePickerNavigationController/predicateForSelectionOfProperty https://developer.apple.com/library/ios/documentation/AddressBookUI/Reference/ABPeoplePickerNavigationController_Class/index.html#//apple_ref/occ/instp/ABPeoplePickerNavigationController/predicateForSelectionOfProperty

Thank you in advance for your help. 预先感谢您的帮助。

Add this where you instantiate the people picker: 在实例化人员选择器的地方添加:

if ([peoplePicker respondsToSelector:@selector(setPredicateForSelectionOfPerson:)])
{
     peoplePicker.predicateForSelectionOfPerson = [NSPredicate predicateWithFormat:@"%K.@count > 1", ABPersonPhoneNumbersProperty];
}

This will only let you choose contacts with 2 or more phone numbers. 这样,您只能选择包含2个或更多电话号码的联系人。 For other contacts, you will be shown the contact details. 对于其他联系人,您将看到联系方式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM