본문 바로가기
프로그래밍 놀이터/iOS

[iOS] 연락처 선택 modal 띄우기

by 돼지왕 왕돼지 2017. 6. 16.
반응형

 [iOS] 연락처 선택 modal 띄우기


https://developer.apple.com/library/ios/documentation/ContactData/Conceptual/AddressBookProgrammingGuideforiPhone/Chapters/QuickStart.html#//apple_ref/doc/uid/TP40007744-CH2-SW1


ABMultiValueCopyValueAtIndex, ABMultiValueGetCount, ABMultiValueRef, ABPeoplePickerNavigationController, abpeoplepickernavigationcontrollerdelegate, abrecordcopyvalue, addressbookui, CFRelease, didSelectPerson, dismissmodalviewcontrolleranimated, header, import, IOS, kABPersonFirstNameProperty, kABPersonPhoneProperty, NSLog, Objective-C, peoplePickerDelegate, peoplePickerNavigationController, peoplePickerNavigationControllerDidCancel, presentModalViewController, protocol, [iOS] 연락처 선택 modal 띄우기, __bridge_transfer, ㅍ, 연락처 선택 modal, 프로토콜, 프로토콜 선언


1. #import <AddressBookUI/AddressBookUI.h>



2. <ABPeoplePickerNavigationControllerDelegate> 프로토콜 선언



3. modal 띄우기

ABPeoplePickerNavigationController *picker = [[ABPeoplePickerNavigationController alloc] init];

picker.peoplePickerDelegate = self;

[self presentModalViewController:picker animated:YES];



4. delegate 함수들 구현

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

    [self dismissModalViewControllerAnimated:YES];

}


- (void)peoplePickerNavigationController:(ABPeoplePickerNavigationController*)peoplePicker didSelectPerson:(ABRecordRef)person{    

NSString *name = (__bridge_transfer NSString*)ABRecordCopyValue(person, kABPersonFirstNameProperty);

NSString *phoneNumber = nil;

ABMultiValueRef phoneNumbers = ABRecordCopyValue(person, kABPersonPhoneProperty);

if (ABMultiValueGetCount(phoneNumbers) > 0){

phone = (__bridge_transfer NSString*) ABMultiValueCopyValueAtIndex(phoneNumbers, 0);

}

CFRelease(phoneNumbers);

[self dismissModalViewControllerAnimated:YES];

NSLog(@“name=%@, phoneNumber=%@“, name, phoneNumber);

}




반응형

댓글