我想创建一个按钮,当按下该按钮时,将打开添加电话应用程序的联系人页面。按下完成/取消按钮后,它应该返回到我的应用程序。我知道这是可能的,但我不知道如何。
答案 0 :(得分:1)
我认为Apple address book programming guide会对您有所帮助:
ABNewPersonViewController *view = [[ABNewPersonViewController alloc] init];
view.newPersonViewDelegate = self;
UINavigationController *newNavigationController = [[UINavigationController alloc]
initWithRootViewController:view];
[self presentModalViewController:newNavigationController
animated:YES];
iOS9不推荐使用ABNewPersonViewController 。一个人应该使用CNContactViewController。不幸的是有一个错误,请参考这个帖子(CNContactViewController Bug)。
CNContactStore().requestAccessForEntityType(.Contacts) {ok, err in
guard ok else {return} // only if access is granted
dispatch_async(dispatch_get_main_queue()) {
let con = CNMutableContact()
let unkvc = CNContactViewController(forUnknownContact: con)
unkvc.contactStore = CNContactStore()
unkvc.delegate = self
unkvc.allowsActions = false
self.presentViewController(unkvc, animated: true, completion: nil)
}
和委托方法:
func contactViewController(vc: CNContactViewController, didCompleteWithContact con: CNContact?)
func contactViewController(vc: CNContactViewController, shouldPerformDefaultActionForContactProperty prop: CNContactProperty) -> Bool