我想在原生联系人应用中提供一个群组,但所有群组查询都不起作用。我可以成功地将联系人添加到地址簿中,但我想为我的应用程序创建自己的单独组。与Facebook如何添加自己的群组类似。
编辑:看起来这些组已添加到默认帐户...有没有办法提供单独的提供商?
提前致谢。
答案 0 :(得分:0)
//Create new group like so:
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);