2014-09-18 6 views
2

사람 선택 도구가있는 ios 7이 있고 ios 8과의 호환성을 추가하려고합니다. 두 방법을 모두 하나에 추가했지만 예상되는 식별자가 잘못되었습니다. 또는 '('는 NSString * 연락처 이름 앞에 여는 괄호에. 어떤 제안은 좋은 것입니다! 관심을 가질만한 사람들을위한ios 7 및 ios 8을 사용하는 사람 선택기

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


    NSString *contactName = CFBridgingRelease(ABRecordCopyCompositeName(person)); 
    self.nameField.text = [NSString stringWithFormat:@"%@", contactName ? contactName : @"No Name"]; 


    ABMultiValueRef phoneRecord = ABRecordCopyValue(person, kABPersonPhoneProperty); 
    CFStringRef phoneNumber = ABMultiValueCopyValueAtIndex(phoneRecord, 0); 
    self.phoneField.text = (__bridge_transfer NSString *)phoneNumber; 
    CFRelease(phoneRecord); 


    ABMultiValueRef email = ABRecordCopyValue(person, kABPersonEmailProperty); 
    CFStringRef emailField = ABMultiValueCopyValueAtIndex(email, 0); 
    self.emailField.text = (__bridge_transfer NSString *)emailField; 
    CFRelease(email); 

    CFDataRef photo = ABPersonCopyImageData(person); 
    UIImage* image = [UIImage imageWithData:(__bridge NSData*)photo]; 
    if(photo) 
     CFRelease(photo); 
    if(image) 
     self.myImageView.image = image; 
    [self dismissViewControllerAnimated:YES completion:nil]; 
    return NO; 
} 

-(BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker 
    shouldContinueAfterSelectingPerson:(ABRecordRef)person property:(ABPropertyID)property 
          identifier:(ABMultiValueIdentifier)identifier 
{ 
    [self dismissViewControllerAnimated:YES completion:nil]; 
    return NO; } 
+0

내가 할 것은 이전 위임 메서드와 새 위임 메서드를 모두 구현하는 것입니다. 오른쪽 하나가 자동으로 호출됩니다. – matt

+0

감사합니다! 그게 내가 생각하는 더 나은 접근 방법이다. –

+0

코드 스 니펫을 업데이트했는데이 문제를 해결하는 방법에 대한 아이디어가 하나있다. –

답변

8

이 내 작업 코드, 모두 IOS 7, IOS 8

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


     NSString *contactName = CFBridgingRelease(ABRecordCopyCompositeName(person)); 
     self.nameField.text = [NSString stringWithFormat:@"%@", contactName ? contactName : @"No Name"]; 


     ABMultiValueRef phoneRecord = ABRecordCopyValue(person, kABPersonPhoneProperty); 
     CFStringRef phoneNumber = ABMultiValueCopyValueAtIndex(phoneRecord, 0); 
     self.phoneField.text = (__bridge_transfer NSString *)phoneNumber; 
     CFRelease(phoneRecord); 


     ABMultiValueRef email = ABRecordCopyValue(person, kABPersonEmailProperty); 
     CFStringRef emailField = ABMultiValueCopyValueAtIndex(email, 0); 
     self.emailField.text = (__bridge_transfer NSString *)emailField; 
     CFRelease(email); 

     CFDataRef photo = ABPersonCopyImageData(person); 
     UIImage* image = [UIImage imageWithData:(__bridge NSData*)photo]; 
     if(photo) 
      CFRelease(photo); 
     if(image) 
      self.myImageView.image = image; 
     [self dismissViewControllerAnimated:YES completion:nil]; 
     return NO; 
    } 



     -(BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker 
      shouldContinueAfterSelectingPerson:(ABRecordRef)person property:(ABPropertyID)property 
            identifier:(ABMultiValueIdentifier)identifier 
     { 
      [self dismissViewControllerAnimated:YES completion:nil]; 
      return NO; } 
에 대한
+0

감사합니다! 이것은 나를 위해 일했다 :) – nithinreddy

0

대리자 메소드의 서명이 새로운 iOS 버전으로 업데이트되면 이전 버전은 wh ile. 대답은 : 새롭고 오래된 방법을 구현하십시오, 맞은 것이 자동적으로 불릴 것입니다.