// 首先要導入下面兩個庫
AddressBook.framework
AddressBookUI.framework
// 導入頭文件
#import <AddressBook/AddressBook.h>
#import <AddressBookUI/AddressBookUI.h>
目標很簡單,就是按Click之後,調用系統聯繫人,然後按“取消”按鈕返回。
下面這段代碼在iOS8之前是好用的。到iOS9就會有問題,就是聯繫人畫面被調出來之後,右上角的[取消]按鈕沒了,導致程序退不回去。
但是把①和②替換,就可以正常使用了。原因還不知道。
// 這是Click按鈕按下時的事件處理
- (IBAction)setOutput:(id)sender {
userOutput.text = userInput.text;
NSLog(@"Press the button");
ABPeoplePickerNavigationController* llViewController = [[ABPeoplePickerNavigationController alloc] init];
[self.view addSubview:llViewController.view]; // ①
// [self presentViewController:llViewController animated:YES completion:nil]; // ②
}
- (void)peoplePickerNavigationControllerDidCancel:(ABPeoplePickerNavigationController *)peoplePicker
{
//[peoplePicker dismissViewControllerAnimated:YES completion:nil];
[self.navigationController popViewControllerAnimated:YES];
}