2

I have an app that adds over 300 contacts to the address book. If I turn around and delete them right after they are added, they dont get fully removed from icloud. They get deleted from the local addressbook initially, but they still get added to icloud. Once they are added in icloud, they get synced back to my local address book. Any idea how I can delete the contacts? If I wait a while (i.e. until all the contacts have actually made it to icloud) it works fine. But if I start deleting them before they are in icloud, they dont all get deleted.

Here is code Im using to read all the contacts from the addressbook - Im checking the name of the contact and if it matches one from my list, I delete it.

ABAddressBookRef addressBook = ABAddressBookCreateWithOptions(NULL, &myError);
NSMutableArray *names=[[NSMutableArray alloc] init];

//Get all names from default contacts list
for (int i=0;i<[AB.defaultContacts count];i++) {
    NSDictionary *plistDict = plistDict = [AB.defaultContacts objectAtIndex:i];
    names[i] = [plistDict objectForKey:@"kABPersonOrganizationProperty"];
}


NSArray *contactArray = (__bridge NSArray *)ABAddressBookCopyArrayOfAllPeopleInSource(addressBook,ABAddressBookCopyDefaultSource(addressBook));

//Search through all actual address book contacts
for (id contact in contactArray) {
    //search name from default contacts list
    for (id name in names) {
        //Get name for current contact from address book
        NSString *tmp=(NSString *)CFBridgingRelease(ABRecordCopyValue(CFBridgingRetain(contact),kABPersonOrganizationProperty));

        //If name from address book matches name from default contacts - zap it
        if ([tmp isEqualToString:name]) {

            ABAddressBookRemoveRecord(addressBook, CFBridgingRetain(contact), nil);
            deletedContacts++;
        }
    }
}
ABAddressBookSave(addressBook, nil);
CFRelease(addressBook);
Marty
  • 162
  • 6

0 Answers0