无法使用ABGroupAddMember将联系人添加到iPhone中的特定组 [英] Unable to add contacts into specific group in iphone using ABGroupAddMember

查看:101
本文介绍了无法使用ABGroupAddMember将联系人添加到iPhone中的特定组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将选定的联系人添加到特定组中,但是无法将联系人添加到组中。
我想创建新的组并将联系人添加到该组中。但是在该组中创建组后无法添加联系人。这是我用于创建新组并将联系人添加到组中的代码:

I am trying to add selected contacts into specific group but contacts cant added in group. I want to create new group and add contacts into that group. but after creating group in that group unable to add contacts.here is my code for create new group and add contacts into group:

    addressBook = ABAddressBookCreateWithOptions(nil, &err);
    group = ABGroupCreate();
    ABRecordSetValue(group, kABGroupNameProperty, txtGroupNameText.text, &err);
    ABAddressBookAddRecord(addressBook, group, &err);
    ABAddressBookSave(addressBook, &err);
    groupId = ABRecordGetRecordID(group);

并用于添加联系人:

        ABRecordRef person = [contactArray objectAtIndex:i];
        ABRecordRef HiByeGroup = ABAddressBookGetGroupWithRecordID(addressBook,       self.groupId);
        BOOL didAdd = ABGroupAddMember(HiByeGroup,person,&err);

        if (didAdd) {
            // Update to handle the error appropriately.
            NSLog(@"Unresolved error while adding person to HiBye group");
        }

        BOOL didSave = ABAddressBookSave(addressBook, &err);

        if (didSave) {
            // Update to handle the error appropriately.
            NSLog(@"Unresolved error while saving address book");
        }

联系人可以保存但无法添加。请帮助我,谢谢。

contacts get save but not getting add.Please help me ,Thanks.

推荐答案

在将其添加到通讯录中之前,您首先需要将其保存到通讯簿中。

You first need to save the Person to the address book before adding it to the group.

例如,尝试下面的代码,它可以很好地工作

for example try this code , it works well

ABAddressBookRef ab = ABAddressBookCreate();
CFErrorRef error;
ABRecordRef group = ABGroupCreate();
ABRecordSetValue(group, kABGroupNameProperty,@"new group", &error);
ABAddressBookAddRecord(ab, group, &error);
ABAddressBookSave(ab, &error);
//Create new person and save to this group
ABRecordRef record = ABPersonCreate();
BOOL isSuccess ;

isSuccess  = ABRecordSetValue(record, kABPersonNicknameProperty,@"GroupMember nick name", &error);
isSuccess = ABRecordSetValue(record, kABPersonMiddleNameProperty, @"Middle name", &error);

ABMutableMultiValueRef copyOfPhones = ABMultiValueCreateMutable(kABPersonPhoneProperty);

CFTypeRef phone= CFSTR("123000222111");

ABMultiValueAddValueAndLabel(copyOfPhones, phone,kABPersonPhoneMobileLabel,NULL);

isSuccess = ABRecordSetValue(record, kABPersonPhoneProperty, copyOfPhones, &error);

isSuccess = ABAddressBookAddRecord(ab, record, &error);
isSuccess = ABAddressBookSave(ab, &error);

ABGroupAddMember(group, record, &error);

NSLog(@"is success %d", isSuccess);

ABAddressBookSave(ab, &error);
CFRelease(group); 

这篇关于无法使用ABGroupAddMember将联系人添加到iPhone中的特定组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆