2014-09-12 23 views
48

XCode'u (6.0, 6A313) ve iOS'umu (8.0, 12A365) iPhone'da gm tohumlarına güncellediğimden beri, ABPeoplePickerNavigationController kodu daha önce olduğu gibi çalışmıyor.ABPeoplePickerNavigationController iOS8 ile değiştiriyor?

  • iOS 7.1.2: Birisi bir kişiyi almak istiyorsanız, adres defteri açılır ve bir toplama sonra, kişiler tam listesini görmek, bir kişinin ayrıntı görünümü açılır ve ekleyebilir daha Almak istediğiniz telefon numarasına bir tıklama ile iletişim kurun.

  • iOS 8.0: onun her şeyi benzer ancak bunu yerine aktarmadan telefon numarasını aramak bir kişinin numarasını tıklayın eğer ..

Kodu:

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

yapamadım Apple iOS geliştirici kitaplığında herhangi bir cevap bulmak. , bunun için başka bir çözüm var mı?

cevap

79

iOS 8 yeni temsilci yöntemi bunun için uygulanacak gerektirir:

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

iOS 7 veya daha önceki desteklemek için yerinde eski temsilci yöntemini tutun.

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

bu temsilci yöntemi değeri eylemi neden dokunarak, iOS 8'de uygulanmazsa: Ne benim app do iOS 8 temsilci yönteminden iOS 7 temsilci yöntemini çağırmak. Uygulandığında, temsilci seçilen değerle çağrılır.

+0

Bu, iOS 8.0.1'de benim için çalışmıyor. Uygulamam gereken başka delege yöntemleri var mı? Temsilcim iptal yönteminin dışında hiç vurulmuyor. – Alexander

+0

@AlexanderCollins Bu, 8.0.1 ile benim için gayet iyi çalışıyor. Temsilcinizin ayarlandığından emin misiniz? – rmaddy

+0

Evet, iptal temsilci yöntemim doğru şekilde vuruluyor. Bir kişinin telefon numarasını seçmek, sadece didSelect: delege yöntemimi kullanmak yerine bu kişiyi arar. – Alexander

13

iOS8 ile de yeni temsilci yöntemi, bakınız:

Ben benim durumumda ne istediğini
- (void)peoplePickerNavigationController:(ABPeoplePickerNavigationController*)peoplePicker didSelectPerson:(ABRecordRef)person; 
{ 
    [self selectedPerson:person]; 
} 

.

+0

Bu benim için de işe yaradı. Teşekkürler! –

+0

İyi çalışıyor, teşekkürler Chris Prince. –

+0

Bu iOS 8 için eksiksiz bir cevaptır. Birisi kabul edilen cevabı düzenlemelidir –

1

Bu, hem iOS 8 hem de iOS 7 ve daha düşük sürümlerde benim için çalıştı.

Not Bu didSelectPerson: (ABRecordRef) kişisini kullanıyorum.

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

} 
İlgili konular