ABPeoplePickerNavigationController verandert met iOS8?

Sinds ik XCode (6.0, 6A313) en mijn iOS (8.0, 12A365) op de iPhone heb geüpdatet naar gm seeds, werkt de ABPeoplePickerNavigationController-code niet zoals voorheen.

  • iOS 7.1.2: Als iemand een contactpersoon wil importeren, wordt het adresboek geopend en ziet u de volledige lijst met contactpersonen, nadat u er een hebt gekozen, wordt de detailweergave van een contactpersoon geopend en kunt u de contactpersoon toevoegen met een klik op het telefoonnummer dat u wilt importeren.

  • iOS 8.0: het lijkt allemaal op elkaar, maar als je op het nummer van een contact klikt, belt het het telefoonnummer in plaats van het te importeren..

Code:

#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];
}

kon geen antwoord vinden in de iOS-ontwikkelaarsbibliotheek van Apple.
heeft iemand anders er een oplossing voor?


Antwoord 1, autoriteit 100%

iOS 8 vereist dat hiervoor een nieuwe gedelegeerde methode wordt geïmplementeerd:

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

Houd de oude methode voor gedelegeerden op zijn plaats om iOS 7 of eerder te ondersteunen. Wat ik in mijn app doe, is de iOS 7-delegate-methode aanroepen vanuit de iOS 8-delegate-methode:

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

Als deze gedelegeerde methode niet is geïmplementeerd in iOS 8, wordt de actie veroorzaakt door op de waarde te tikken. Wanneer geïmplementeerd, wordt de gemachtigde in plaats daarvan gebeld met de geselecteerde waarde.


Antwoord 2, autoriteit 16%

Zie ook de gedelegeerde methode, nieuw met iOS8:

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

Dat is wat ik wilde in mijn geval.


Antwoord 3

Dit werkte voor mij op zowel iOS 8 als iOS 7 en lager.

Opmerking: ik gebruik in plaats daarvan deze didSelectPerson:(ABRecordRef)person.

//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
}

Other episodes