hi i’m studying a iOS programming, but i have a trouble
i want to make a contact group, and add my address book.
but the problem is my code works on simulator, but iPhone doesn’t.
i don’t know why is that, here’s my code
-(void) createAGroupInContact:(NSString *)aGroupName
{
CFErrorRef error = NULL;
ABAddressBookRef addressBook = ABAddressBookCreate();
ABRecordRef group = ABGroupCreate();
if(ABRecordSetValue(group, kABGroupNameProperty, aGroupName, &error)) {
NSLog(@"setValue ok"); //set value is succeed on iPhone and simulator both.
else {
NSLog(@"setValue fail");
}
if(ABAddressBookAddRecord(addressBook, group, &error)) {
// when i run my code on simulator, group is saved.
NSLog(@"group save ok");
}
else {
// but when i run my code on iPhone, group doesn't save
NSLog(@"group save fail");
NSLog(@"error = %@", error); // it printed error = (null)
}
if(ABAddressBookSave(addressBook, &error)) {
NSLog(@"save ok");
}
else {
NSLog(@"save fail");
}
CFRelease(group);
CFRelease(addressBook);
}
i try to solve this problem myself, but can’t.
why this code success on simulator successfully, but why doesn’t on iPhone?
is anywhere do i fix it? how can i fix it? please help me
Some AddressBook sources do not support group creation. Do you sync with MS Exchange or anything similar on your iPhone?