How to delete a contact from address book in iPhone using objective-c?

后端 未结 3 620
情话喂你
情话喂你 2020-12-22 01:24

I want to delete a contact from the address book in iPhone how can we do that ?

Thanks

3条回答
  •  爱一瞬间的悲伤
    2020-12-22 01:37

    Here is a sample code to do the same:

    - (void)delAllContacts {
        ABAddressBookRef addressBook = CFBridgingRetain((__bridge id)(ABAddressBookCreateWithOptions(NULL, NULL)));
        int count = ABAddressBookGetPersonCount(addressBook);
        if(count==0 && addressBook!=NULL) { //If there are no contacts, don't delete
            CFRelease(addressBook);
            return;
        }
        //Get all contacts and store it in a CFArrayRef
        CFArrayRef theArray = ABAddressBookCopyArrayOfAllPeople(addressBook);
        for(CFIndex i=0;i

提交回复
热议问题