今天寫代碼遇到了要調用系統通訊錄,看了一些博客發現寫的都是獲取通訊錄的內容,而不是調用系統的界面.
分享一下自己寫的代碼
第一步:引入
#import #import
#pragma mark -- IBAction - (IBAction)buttonClicked:(id)sender { ABPeoplePickerNavigationController *peoplePicker = [[ABPeoplePickerNavigationController alloc] init]; peoplePicker.peoplePickerDelegate = self; [self presentViewController:peoplePicker animated:YES completion:nil]; }第三步:實現代理方法ABPeoplePickerNavigationControllerDelegate
#pragma mark -- ABPeoplePickerNavigationControllerDelegate - (void)peoplePickerNavigationController:(ABPeoplePickerNavigationController*)peoplePicker didSelectPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier { ABMultiValueRef valuesRef = ABRecordCopyValue(person, kABPersonPhoneProperty); CFIndex index = ABMultiValueGetIndexForIdentifier(valuesRef,identifier); CFStringRef value = ABMultiValueCopyValueAtIndex(valuesRef,index); [self dismissViewControllerAnimated:YES completion:^{ self.textField.text = (__bridge NSString*)value; }]; }這裡需要說明一下的是 這裡提供的方法開始適用於iOS8