Aldo Lazuardi Aldo Lazuardi - 3 months ago 62
iOS Question

preload/show data in CNContactViewController (swift)

Could we show data in ios editor/CNContactViewController instead only show blank textfields?

for example, when I open CNContactViewController I want the name to be filled before user type anything

Answer

Yes, It is possible. Using viewControllerForNewContact: method of CNContactViewController, you can pass a CNContact object.

So in order to show name as filled in view, create a contact object with name and pass to viewControllerForNewContact:

CNMutableContact *pNewContact          = [[CNMutableContact alloc] init];
pNewContact.givenName                  = @"My Name";
CNContactViewController *pNewContactVC = [CNContactViewController viewControllerForNewContact:pNewContact];
UINavigationController *pNavController = [[UINavigationController alloc] initWithRootViewController:pNewContactVC];
[self presentViewController:pNavController animated:YES
                 completion:nil];

Please see https://developer.apple.com/library/ios/documentation/ContactsUI/Reference/CNContactViewController_Class/#//apple_ref/occ/clm/CNContactViewController/viewControllerForNewContact: