[iOS] 연락처 선택 modal 띄우기
https://developer.apple.com/library/ios/documentation/ContactData/Conceptual/AddressBookProgrammingGuideforiPhone/Chapters/QuickStart.html#//apple_ref/doc/uid/TP40007744-CH2-SW1
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);
}
'프로그래밍 놀이터 > iOS' 카테고리의 다른 글
[iOS] CFArray 에서 CF 가 뭔가요? (0) | 2017.06.18 |
---|---|
[iOS] NS_AVAILABLE_IOS 와 NS_DEPRECATED_IOS 의 의미는? (0) | 2017.06.17 |
[iOS] keyboard type 바꾸기 (0) | 2016.09.19 |
[iOS Study] NSUserDefaults (2) | 2016.03.27 |
[iOS Study] 상태 복원 (0) | 2016.03.26 |
댓글