ABGroupCreate problem [duplicate]
I have problem with a开发者_如何学编程dding a group to the iOS address book. In the simulator everything works great, I add the group, and assign contacts to it. But when the same application runs on an iPhone or iPad the group is not created and the new contacts are therefore not assigned to that specific group.
The method ABGroupCreate does not return any error.
Solution please? :)
Since you didn't paste your code, i can not know the problem. anyway- this is a method i use in my apps, it creates a group and return its ID so you can store it for later use, works great for me-
-(NSInteger) createNewGroup:(NSString*)groupName {
ABAddressBookRef addressBook = ABAddressBookCreate();
ABRecordRef newGroup = ABGroupCreate();
ABRecordSetValue(newGroup, kABGroupNameProperty,groupName, nil);
ABAddressBookAddRecord(addressBook, newGroup, nil);
ABAddressBookSave(addressBook, nil);
NSInteger groupId = ABRecordGetRecordID(newGroup);
CFRelease(addressBook);
CFRelease(newGroup);
return groupId;
}
Good luck shani
精彩评论