ABPeoplePickerNavigationController更改与iOS8?
由于我已经更新iPhone上的XCode(6.0,6A313)和iOS(8.0,12A365)gm种子,ABPeoplePickerNavigationController代码不像以前那样工作。
-
iOS 7.1.2:如果有人想导入一个联系人,地址簿打开,你看到联系人的完整列表,select一个后,它打开联系人的详细信息视图,比你可以添加联系人点击的手机您想要导入的号码。
-
iOS 8.0:它的一切类似,但如果你点击一个联系人的号码,拨打电话号码,而不是导入它..
码:
#pragma mark - AddressBook Delegate Methods -(BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person{ return YES; } -(BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier{ // Get the first and the last name. Actually, copy their values using the person object and the appropriate // properties into two string variables equivalently. // Watch out the ABRecordCopyValue method below. Also, notice that we cast to NSString *. NSString *firstName = (__bridge NSString *)ABRecordCopyValue(person, kABPersonFirstNameProperty); NSString *lastName = (__bridge NSString *)ABRecordCopyValue(person, kABPersonLastNameProperty); // Compose the full name. NSString *fullName = @""; // Before adding the first and the last name in the fullName string make sure that these values are filled in. if (firstName != nil) { fullName = [fullName stringByAppendingString:firstName]; } if (lastName != nil) { fullName = [fullName stringByAppendingString:@" "]; fullName = [fullName stringByAppendingString:lastName]; } // Get the multivalue number property. CFTypeRef multivalue = ABRecordCopyValue(person, property); // Get the index of the selected number. Remember that the number multi-value property is being returned as an array. CFIndex index = ABMultiValueGetIndexForIdentifier(multivalue, identifier); // Copy the number value into a string. NSString *number = (__bridge NSString *)ABMultiValueCopyValueAtIndex(multivalue, index); nameTextField.text = fullName; numberTextField.text = number; // Dismiss the contacts view controller. [_addressBookController dismissViewControllerAnimated:YES completion:nil]; return NO; } // Implement this delegate method to make the Cancel button of the Address Book working. -(void)peoplePickerNavigationControllerDidCancel:(ABPeoplePickerNavigationController *)peoplePicker{ [_addressBookController dismissViewControllerAnimated:YES completion:nil]; }
在苹果的iOS开发者库中找不到任何答案。 有别人的解决办法吗?
iOS 8需要为此执行一个新的委托方法:
- (void)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker didSelectPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier { }
保留旧的委托方法,以支持iOS 7或更早版本。 我在我的应用程序中所做的是从iOS 8委托方法调用iOS 7委托方法:
- (void)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker didSelectPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier { [self peoplePickerNavigationController:peoplePicker shouldContinueAfterSelectingPerson:person property:property identifier:identifier]; }
如果这个委托方法没有在iOS 8中实现,则点击该值将导致该操作。 实施时,代表被调用,而select的值。
另请参阅iOS8新增的委托方法:
- (void)peoplePickerNavigationController:(ABPeoplePickerNavigationController*)peoplePicker didSelectPerson:(ABRecordRef)person; { [self selectedPerson:person]; }
这就是我想要的。
这在iOS 8和iOS 7以及更低版本上都适用于我。
注意我正在使用这个didSelectPerson:(ABRecordRef)人来代替。
//Needed for iOS 8 - (void)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker didSelectPerson:(ABRecordRef)person { NSLog(@"Went here 1 ..."); [self peoplePickerNavigationController:peoplePicker shouldContinueAfterSelectingPerson:person]; } //needed for iOS 7 and lower - (BOOL)peoplePickerNavigationController: (ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person { NSLog(@"Went here 2 ..."); //add your logic here }