ABAddressBook联系人未正确与icloud同步

时间:2012-11-06 04:13:39

标签: iphone ios icloud abaddressbook

我有一个应用程序,可以为地址簿添加300多个联系人。如果我在添加后立即转身并删除它们,它们就不能完全从icloud中删除。它们最初会从本地地址簿中删除,但它们仍会被添加到icloud中。一旦将它们添加到icloud中,它们就会同步回我当地的地址簿。知道如何删除联系人吗?如果我等待一段时间(即直到所有的联系人实际上已经使它成为icloud)它工作正常。但如果我在icloud之前开始删除它们,它们都不会被删除。

以下是用于从地址簿中读取所有联系人的代码 - 我正在检查联系人的姓名,如果它与我的列表中的匹配,我将其删除。

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);

0 个答案:

没有答案