Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to open New Contact Screen Directly?

enter image description here Can any one please guide me ? Is it possible to open contact screen programmatically in iOS (swift)

like image 894
Bucket Avatar asked May 18 '17 11:05

Bucket


3 Answers

Try this below code. I think I am getting what you are looking for.

    let con = CNContact()
    let vc = CNContactViewController(forNewContact: con)
    _ = self.navigationController?.pushViewController(vc, animated: true)
like image 171
Rishab Avatar answered Oct 19 '22 22:10

Rishab


Its possible to open this screen directly with some pre populated fields. No need of any workarounds.

let contact = CNMutableContact()
let homePhone = CNLabeledValue(label: CNLabelHome, value: CNPhoneNumber(stringValue :"number goes here"))
contact.phoneNumbers = [homePhone]
contact.imageData = data // Set image data here
let vc = CNContactViewController(forNewContact: contact)
vc.delegate = self
let nav = UINavigationController(rootViewController: vc)
self.present(nav, animated: true, completion: nil)
like image 5
Murali Avatar answered Oct 20 '22 00:10

Murali


Till iOS 10.3.1 there is no public api to open contacts screen directly to add new contact. You can use ContactsUI framework to open contacts within your application and then from that contact screen add new Contact.

For reference :-

https://developer.apple.com/reference/contactsui

like image 1
Himanshu Avatar answered Oct 19 '22 23:10

Himanshu