【问题标题】:Display contact properties if it has more than one phone number with ios8ios8 如果有多个电话号码,则显示联系人属性
【发布时间】:2014-09-25 15:56:21
【问题描述】:

在 ios8 中,如果他有多个电话号码,我想访问联系人属性,但我不知道如何在 iOS8 中进行。

这是我在 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;
    }

}

我知道我必须使用 iOS8 中的 didSelectPerson 方法,但我不知道如何告诉应用程序在选择 iOS7 中的人后可以继续。

我在苹果文档上阅读了 predicateForSelectionOfPerson 的内容,但我不明白如何使用它。

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

提前感谢您的帮助。

【问题讨论】:

    标签: ios ios8 abpeoplepickerview


    【解决方案1】:

    在你实例化人物选择器的地方添加这个:

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

    这只会让您选择具有 2 个或更多电话号码的联系人。对于其他联系人,您将看到联系方式。

    【讨论】:

    • 谢谢!这就是我需要的!情况正好相反(“%K.@count
    • 你可能还需要: if ([picker respondsToSelector: @selector(setPredicateForEnablingPerson:)]) { picker.predicateForEnablingPerson = [NSPredicate predicateWithFormat:@"emailAddresses.@count > 0"];没有它,我的应用根本不会选择联系人
    • @Leep 当我添加("%K.@count < 2") 时,所有少于2个电话号码的联系人都是灰色的。
    猜你喜欢
    • 1970-01-01
    • 2017-11-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多