2014-09-12 14 views
48

Od czasu aktualizacji XCode (6.0, 6A313) i mojego iOS (8.0, 12A365) na iPhone'a do nasion gm, kod ABPeoplePickerNavigationController nie działa tak jak wcześniej.ABPeoplePickerNavigationController zmiany z iOS8?

  • iOS 7.1.2: Jeśli ktoś chce importować kontakt, książka adresowa otwiera i można zobaczyć pełną listę kontaktów, po wybranie jednej, otwiera widok szczegółów styk i nie można dodać skontaktować się z kliknięciem numeru telefonu, który chcesz zaimportować.

  • iOS 8.0: jej wszystko podobne, ale jeśli klikniesz na liczbę styk to wybrać numer telefonu zamiast importować go ..

Kod:

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

nie mógł znajdź odpowiedź w bibliotece programistów Apple na iOS. ma ktoś inny rozwiązanie dla niego?

Odpowiedz

79

iOS 8 wymaga nowa metoda delegat być realizowane za to:

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

zachować starą metodę delegata w celu wsparcia iOS 7 lub wcześniej. Co mogę zrobić w mojej aplikacji jest wywołać metodę delegata iOS 7 z iOS metodzie 8 Delegat:

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

Jeśli ta metoda delegat nie jest zaimplementowana w iOS 8, wybierając wartość powoduje akcję. Po zaimplementowaniu wywoływana jest zamiast tego z wybraną wartością.

+0

To nie działa dla mnie w iOS 8.0.1. Czy są inne metody delegatów, które muszę wdrożyć? Mój delegat w ogóle nie jest trafiony, z wyjątkiem metody anulowania. – Alexander

+0

@AlexanderCollins Działa to dobrze dla mnie z 8.0.1. Czy jesteś pewien, że Twój delegat jest ustawiony? – rmaddy

+0

Tak, moja metoda delegowania anulowania jest trafiona poprawnie. Wybieranie numeru telefonu kontaktu po prostu wywołuje ten kontakt zamiast uderzać w wybraną metodę didSelect: delegate. – Alexander

13

Zobacz także metodę delegata nowy z systemów iOS 8:

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

To co chciałem w moim przypadku.

+0

To też zadziałało dla mnie. Dzięki! –

+0

Działa dobrze, dzięki Chris Prince. –

+0

To jest kompletna odpowiedź dla systemu iOS 8. Ktoś musi edytować zaakceptowaną odpowiedź –

1

To działało dla mnie zarówno na iOS 8, jak i iOS 7 i niższych.

Uwaga Używam zamiast tego osoby 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 

} 
Powiązane problemy