[ios, Objectiv_C]ABPeoplePickerNavigationController Image 가져오기
일단 헤더 파일에 델리게이트를 등록해준다.
ABPeoplePickerNavigationControllerDelegate 를 추가
다음 m 파일로 가서
- (void)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker didSelectPerson:(ABRecordRef)person
property:(ABPropertyID)property
identifier:(ABMultiValueIdentifier)identifier{
UIImage *photo = nil;
// 주소록에 사람이미지가 있을 경우 저장 , 없을 경우 해당 이미지 삭제
if(ABPersonHasImageData(person)){
CFDataRef imgRef = ABPersonCopyImageDataWithFormat(person,kABPersonImageFormatOriginalSize);
photo = [self fixrotation:[UIImage imageWithData:(__bridge NSData*)imgRef]];
}
만들고
전화번호부를 띄워보자
이함수는 제가 만든 함수로
[self showPeoplePickerController] 를 호출해 주면 된다
-(void)showPeoplePickerController
{
ABPeoplePickerNavigationController *picker = [[ABPeoplePickerNavigationController alloc] init];
picker.peoplePickerDelegate = self;
// Display only a person's phone, email
// picker.displayedProperties = [NSArray arrayWithObjects:
// //[NSNumber numberWithInt:kABPersonFirstNameProperty],
// //[NSNumber numberWithInt:kABPersonLastNameProperty],
// [NSNumber numberWithInt:kABPersonPhoneProperty],
// //[NSNumber numberWithInt:kABPersonEmailProperty],
// nil];
[self presentModalViewController:picker animated:YES];
}
주석 처리한 부분을 풀게 되면 이미지를 가져올수없다. 이부분때문에 3일간 고생했다.
권한 문제인데 ios초보라 좀 걸렸다. 사실 별거 아니였다 모국어가 영어였다면 좋았을것을...