2014-09-24 12 views
6

Ich habe eine Unterklasse von ABPeoplePickerNavigationController, um die Auswahl einer Kontakttelefonnummer in meiner App zu übernehmen. Unter iOS 7 und höher funktioniert alles super.Ich kann keinen Kontakt unter iOS 8 auswählen

Auf iOS 8 wird jedoch meine ABPeoplePickerNavigationControllerDelegate nicht getroffen, wenn Sie eine Telefonnummer auswählen. Stattdessen ruft es nur diese Telefonnummer an.

Ich bemerkte, dass die Methode, die ich verwendete, um die Kontaktauswahl in iOS 7 (peoplePickerNavigationController:shouldContinueAfterSelectingPerson:property:identifier:) zu behandeln, in iOS 8 veraltet war. Diese Methode wurde durch peoplePickerNavigationController:didSelectPerson:property:identifier: ersetzt.

Ich weiß, dass mein Delegat festgelegt ist, da ich den Methodenrückruf peoplePickerNavigationControllerDidCancel: erfolgreich erhalte.

Hat noch jemand dieses Problem erlebt?

Hier ist ein Code-Snippet meiner ABPeoplePickerNavigationController Unterklasse:

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

    [self peoplePickerNavigationController:peoplePicker shouldContinueAfterSelectingPerson:person property:property identifier:identifier]; 
} 

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

    ...do stuff... 

    return NO; 
} 

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

    return YES; 
} 

- (void)peoplePickerNavigationControllerDidCancel:(ABPeoplePickerNavigationController *)peoplePicker { 

    [self dismissViewControllerAnimated:self.shouldAnimateDismiss completion:NULL]; 
} 
+0

Was haben Sie angegeben 'predicateForSelectionOfProperty'? – Rob

+0

Bauen Sie mit Xcode 6 und hat Ihr Projekt ein Base SDK von iOS 8? – rmaddy

+0

@Rob Nichts. Es hat immer funktioniert, ohne das einzustellen. – Alexander

Antwort

6

Wo geben Sie an die peoplePickerDelegate?

In iOS 8, wenn Sie peoplePickerDelegate in viewDidLoad angeben, erleben Sie das merkwürdige Verhalten, das Sie beschreiben (Abbrechen Delegierten arbeiten, die didSelect... und shouldContinue... nicht). Wenn Sie peoplePickerDelegate unmittelbar nach init (oder während) angeben, funktioniert es einwandfrei.

Dies scheint ein iOS 8 "Feature" zu sein. Ich werde einen Fehlerbericht einreichen.

+0

Das war mein Problem. Vielen Dank!! Dies ist in der Tat eine sehr merkwürdige Veränderung. – Alexander

+0

Mein Problem war, dass ich 'picker.delegate = self' anstelle von' picker.peoplePickerDelegate = self' spezifizierte. – kev

+0

@Rob Hallo Sir ich mache alles in Ordnung in meinem Projekt Ich gebe PeoplePickerDelegate auf Knopfklick Methode, aber jetzt Abbrechen Methode funktioniert gut, aber (BOOL) Peoplepickernavigationcontroller nicht aufgerufen. –

0

Nichts würde passieren, wenn ich einen Kontakt in IOS8 wählte.

fand ich neben

if ([picker respondsToSelector:@selector(setPredicateForSelectionOfPerson:)]) 
    { 
     picker.predicateForSelectionOfPerson = [NSPredicate predicateWithFormat:@"[email protected] = 1"]; 
    } 

, dass ich Wenn Sie Sie dies will, um nur Namen dieser Person auch

if ([picker respondsToSelector:@selector(setPredicateForEnablingPerson:)]) 
    { 
     picker.predicateForEnablingPerson = [NSPredicate predicateWithFormat:@"[email protected] > 0"]; 
    } 

Quelle https://developer.apple.com/library/prerelease/ios/samplecode/PeoplePicker/Listings/PeoplePicker_AAPL_8or7_EmailPickerViewController_m.html

0

erforderlich machen:

-(IBAction)btnGetContact{ 
    ABPeoplePickerNavigationController *personPicker = [ABPeoplePickerNavigationController new]; 
    personPicker.peoplePickerDelegate = self; 
    [self presentViewController:personPicker animated:YES completion:nil]; 
} 

-(void)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person{ 
     NSString *firstName; 
    NSString *middleName; 
    NSString *lastName; 
    UIImage *retrievedImage; 

    // get the first name 
    firstName = (__bridge_transfer NSString *)ABRecordCopyValue(person, kABPersonFirstNameProperty); 

    //get the middle name 
    middleName = (__bridge_transfer NSString*)ABRecordCopyValue(person, kABPersonMiddleNameProperty); 

    // get the last name 
    lastName = (__bridge_transfer NSString *)ABRecordCopyValue(person, kABPersonLastNameProperty); 

    // get personPicture 
    if (person != nil && ABPersonHasImageData(person)) 
    { 
     retrievedImage = [UIImage imageWithData:(__bridge_transfer NSData*)ABPersonCopyImageDataWithFormat(person, kABPersonImageFormatThumbnail)]; 
    } 
    else 
    { 
     retrievedImage = nil; 
    } 
} 

Aber wenn Sie zu dieser Person Detail zu gehen suchen Person Zahlen zu erhalten, sollten Sie BOOL statt void für peoplePickerNavigationController verwenden und YES wie unten passieren:

-(BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person{ 
    return YES; 
} 



-(void) peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker didSelectPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier{ 
     ABMutableMultiValueRef phoneno = ABRecordCopyValue(person, kABPersonPhoneProperty); 

CFStringRef phone = ABMultiValueCopyValueAtIndex(phoneno, identifier); 

     _mPhone.text = (__bridge NSString *)phone; 

     [self dismissViewControllerAnimated:NO completion:^(){}]; 
    } 

Auch vergessen Sie nicht AddressBook.framework und AddressBookUI.framework zu einem Projekt zu importieren und ABPeoplePickerNavigationControllerDelegate ,

#import <AddressBook/AddressBook.h> 
#import <AddressBookUI/AddressBookUI.h> 

zu Ihrer Header-Datei.