Objective-C
iOS

iOS8でABPeoplePickerNavigationControllerの変更点

More than 1 year has passed since last update.

変更点

iOS7まで呼ばれていた以下のデリゲートメッソドが呼ばれなくなった。

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

- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier

iOS8では以下のデリゲートメッソドとプロパティが新しく追加された。

- (void)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker didSelectPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier

- (void)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker didSelectPerson:(ABRecordRef)person


@property(nonatomic,copy) NSPredicate *predicateForEnablingPerson
@property(nonatomic,copy) NSPredicate *predicateForSelectionOfPerson
@property(nonatomic,copy) NSPredicate *predicateForSelectionOfProperty

既存コードの対応方法

1、新しく追加されたpeoplePickerNavigationController:didSelectPersonメッソド内で既存のpeoplePickerNavigationController:shouldContinueAfterSelectingPersonを呼ぶ。

- (void)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker didSelectPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier
{
    [self peoplePickerNavigationController:peoplePicker shouldContinueAfterSelectingPerson:person property:property identifier:identifier];
}

- (void)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker didSelectPerson:(ABRecordRef)person
{
    [self peoplePickerNavigationController:peoplePicker shouldContinueAfterSelectingPerson:person];
}

2、peoplePickerNavigationController:shouldContinueAfterSelectingPersonの戻り値で行った制御は新しいプロパティで行う

peoplePicker.predicateForSelectionOfPerson = [NSPredicate predicateWithFormat:@"%K.@count <= 1", ABPersonPhoneNumbersProperty];

//peoplePicker.predicateForSelectionOfPerson = [NSPredicate predicateWithFormat:@"%K.@count <= 1", ABPersonEmailAddressesProperty];

問題点

Blockを利用してpredicateを設定するとアプリが終了しちゃう、、、

peoplePicker.predicateForSelectionOfPerson = [NSPredicate predicateWithBlock:^BOOL(id evaluatedObject, NSDictionary *bindings) {
    return YES;
}];

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'NSBlockPredicate cannot be encoded or decoded'