2014-09-12 6 views
48

gm 씨앗에 iPhone에서 XCode (6.0, 6A313) 및 iOS (8.0, 12A365)를 업데이트 했으므로 ABPeoplePickerNavigationController 코드가 이전과 같이 작동하지 않습니다.ABPeoplePickerNavigationController가 iOS8로 변경 되었습니까?

  • 아이폰 OS 7.1.2 : 누군가가 연락처를 가져 오려면, 주소록이 열리고 하나를 따기 후, 연락처의 전체 목록을 보려면, 그것은 연락처의 상세보기를 열고 당신은 추가 할 수있는 것보다 가져 오려는 전화 번호를 클릭하십시오.

  • 아이폰 OS 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 개발자 라이브러리에서 답변을 찾으십시오. 누군가 다른 사람에게 해결책이 있습니까?

답변

79

아이폰 OS 8은 새로운 위임 방법이 구현 될 필요

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

이 아이폰 OS 7 또는 이전 버전을 지원하는 대신에 기존의 대리자 메서드를 유지합니다.

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

이 대리자 메서드는 값이 동작을 일으키는 도청, 아이폰 OS 8에 구현되어 있지 않은 경우 : 내가 내 응용 프로그램에서하는 것은 아이폰 OS 8 대리자 메서드에서 아이폰 OS 7 대리자 메서드를 호출합니다. 구현 될 때 위임 값이 선택된 값 대신 호출됩니다.

+0

iOS 8.0.1에서는 작동하지 않습니다. 구현해야하는 다른 대리자 메서드가 있습니까? cancel 메서드를 제외하고는 내 대리자가 전혀 공격을받지 않습니다. – Alexander

+0

@AlexanderCollins 8.0.1에서는 잘 작동합니다. 당신의 대의원이 설정되어 있습니까? – rmaddy

+0

그래, 내 취소 대리인 메서드가 제대로 때리고있다. 연락처의 전화 번호를 선택하면 내 didSelect : delegate 메소드를 누르는 대신 해당 연락처가 호출됩니다. – Alexander

13

는 iOS8의와 함께 새로운 대리자 메서드를 참조하십시오

내 경우에는 원 무엇
- (void)peoplePickerNavigationController:(ABPeoplePickerNavigationController*)peoplePicker didSelectPerson:(ABRecordRef)person; 
{ 
    [self selectedPerson:person]; 
} 

.

+0

이것은 나에게도 효과가있다. 감사! –

+0

작동 음, 고마워 크리스 프린스. –

+0

이것은 iOS 8에 대한 완전한 대답입니다. 누군가 허용 된 답변을 편집해야합니다. –

1

이것은 iOS 8 및 iOS 7 이하 모두에서 저에게 효과적이었습니다.

참고이 대신 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 

}