1

I am trying to create a group in my local address book.

I have successfully implemented the code, and it does work well under iOS6 and iOS7 on 32 bit architecture.

However the same code won't do anything on a 64 bit iPad 4. Has anybody experienced something like this?

Here is the code for creating the group:

CFErrorRef error = NULL;
ABRecordRef newGroup = ABGroupCreate();
bool isSucces;
NSLog(@"newGroup: %@", newGroup);
isSucces = ABRecordSetValue(newGroup, 
                            kABGroupNameProperty,  
                            @"KONTAKT", 
                            &error);
if(!isSucces) NSLog(@"error at setting group value");
isSucces = ABAddressBookAddRecord(addressBook, newGroup, &error);
if(!isSucces)NSLog(@"error at adding record to addressbook");
ABAddressBookSave(addressBook, &error);
ekad
  • 14,436
  • 26
  • 44
  • 46
dirtydanee
  • 6,081
  • 2
  • 27
  • 43

1 Answers1

0

try this

 bool foundIt = NO;

    CFArrayRef mygroups = ABAddressBookCopyArrayOfAllGroups(addrBook);
    CFIndex numGroups = CFArrayGetCount(mygroups);
    for(CFIndex idx=0; idx<numGroups; ++idx) {
        ABRecordRef mygroupItem = CFArrayGetValueAtIndex(mygroups, idx);

        CFStringRef name = (CFStringRef)ABRecordCopyValue(mygroupItem, kABGroupNameProperty);
            bool isMatch = [newName isEqualToString:(NSString *)name];
        CFRelease(name);

        if(isMatch) {

            groupNum = [NSNumber numberWithInt:ABRecordGetRecordID(mygroupItem)];
            [self setObject:groupNum forKey:kGroupID];
            foundIt = YES;
            break;
        }
    }
    CFRelease(mygroups);

    if(!foundIt) {

        ABRecordRef mygroupItem = ABGroupCreate();
        ABRecordSetValue(mygroupItem, kABGroupNameProperty, (CFStringRef *)newName, &error);
        if(!error) {
            ABAddressBookAddRecord (addrBook, mygroupItem, &error);    
            ABAddressBookSave(addrBook, &error);

            groupNum = [NSNumber numberWithInt:ABRecordGetRecordID(groupItem)];

            [self setObject:groupNum forKey:kGroupID];
        }
        CFRelease(mygroupItem);
    }
Sport
  • 8,570
  • 6
  • 46
  • 65
  • https://developer.apple.com/library/ios/DOCUMENTATION/ContactData/Conceptual/AddressBookProgrammingGuideforiPhone/Introduction.html refer this – Sport Feb 20 '14 at 13:53
  • i have done some further debugging, and ABAddressBookAddRecord(addressBook, newGroup, &error); returns false value. So i think that should cause the problem. @Sport: thx for the sample code, like i sad i have managed to get it work on most devices, and the problem is on a 64 bit iPad device. – dirtydanee Feb 20 '14 at 14:39