开发者

Remove a group from Addressbook

开发者 https://www.devze.com 2023-03-22 01:20 出处:网络
I have create some groups in addressbook in code. I use the code below to remove a specific group. ABAddressBookRemoveRecord() returns YES. but the group is still there!

I have create some groups in addressbook in code. I use the code below to remove a specific group. ABAddressBookRemoveRecord() returns YES. but the group is still there! What is wrong with the code?

BOOL res;
CFErrorRef error;
ABAddressBookRef ab = ABAddressBookCreate();

NSArray *groups = (NSArray *) ABAddressBookCopyArrayOfAllGroups(ab);

for (id _group in groups)
{
    NSString *currentGroupName = [[NSString alloc] init];
    currentGroupName = (NSString*) ABRecordCopyValue(_group, kABGroupNameProperty);

    if ([groupName isEqualToString:currentGroupName])
    {
        [currentGroupName release];
        res = ABAddressBookRemoveRecord(ab, _group, &error);
        return res;
    }
    [currentGroupName release];开发者_JAVA百科
}

return NO;


add this ABAddressBookSave(ab, nil); before return res;

0

精彩评论

暂无评论...
验证码 换一张
取 消