iOS - add contact into Contacts?

前端 未结 3 1973
故里飘歌
故里飘歌 2020-12-07 10:26

Heyo! Is there a way how when a user taps a button it can add or update a contact into the actual Apple Contacts Book? Some festivals have email responses include a \"name c

3条回答
  •  抹茶落季
    2020-12-07 11:08

    To present default contact controller

    Step 1: Add ContactUi.framework into project and import

        #import 
        #import 
    

    Step2: Add this code

     -(void)showAddContactController{
            //Pass nil to show default contact adding screen
            CNContactViewController *addContactVC = [CNContactViewController viewControllerForNewContact:nil];
            addContactVC.delegate=self;
            UINavigationController *navController   = [[UINavigationController alloc] initWithRootViewController:addContactVC];
            [viewController presentViewController:navController animated:NO completion:nil];
        }
    

    Step3:

    For getting call back when pressing DONE or CANCEL, Add and implement the delegate method.

    - (void)contactViewController:(CNContactViewController *)viewController didCompleteWithContact:(nullable CNContact *)contact{
        //You will get the callback here
    }
    

提交回复
热议问题