我正在开发一个处理iPhone联系人群组的iPhone应用程序,但正如我所观察到的那样,在iPhone联系人中无法创建群组,但在SDK中我们已经获得了创建和管理群组的框架,因此我决定从应用程序界面创建组并将联系人添加到创建的组。
任何人都可以帮助如何在iPhone联系人中创建群组,或者我的方法是否正确,可以从应用创建群组?
答案 0 :(得分:1)
如果您找到了解决方案,建议关闭此问题。如果没有,以下代码供您参考:
- (void)addNewGroup:(NSString *)groupName
{
ABAddressBookRef addressBook = ABAddressBookCreate();
ABRecordRef newGroup = ABGroupCreate();
// Save groupName into ABRecord
CFErrorRef error = NULL;
BOOL result = ABRecordSetValue(newGroup, kABGroupNameProperty, (CFTypeRef)groupName, &error);
if (!result)
{
NSLog(@"Failed to create new group reference with error, %@", error);
CFRelease(addressBook);
return;
}
result = ABAddressBookAddRecord(addressBook, newGroup, &error);
if (!result)
{
NSLog(@"Failed to save new group record to address book with error, %@", error);
CFRelease(addressBook);
return;
}
result = ABAddressBookSave(addressBook,&error);
if (!result)
{
NSLog(@"Failed to save change back to address book with error, %@", error);
}
CFRelease(addressBook);
}