Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7748553
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T10:48:55+00:00 2026-06-01T10:48:55+00:00

I have a problem when I run this snippet of code on the emulator

  • 0

I have a problem when I run this snippet of code on the emulator it works, and I get the id of the group but when I run it on a device the id is set to -1 … but the error message stays null.

    -(NSNumber *)addGroupeToAddressbookWithName:(NSString *)name{
    ABAddressBookRef addressBook = ABAddressBookCreate();
    CFErrorRef error = NULL;
    ABRecordRef group = ABGroupCreate();
    ABRecordSetValue(group, kABGroupNameProperty,(__bridge CFStringRef)name, &error);
    ABAddressBookAddRecord(addressBook, group, &error);
    ABAddressBookSave(addressBook,&error);
    NSNumber *gId = [NSNumber numberWithInt:ABRecordGetRecordID(group)];

    CFRelease(group);
    return gId;
}

I can’t figure out what the difference is and how to make it work on a real device.

EDIT: Found that it works if I remove the exchange sync on my phone, but still want it to work while being able to have a exchange account on the phone. So not really solving the problem

EDIT / Answer

Found that it was because exchange don’t know about groups, to save a group it is needed to use the right source, also see : Obtaining Specific ABSource from ABAddressBook in iOS 4+

new code:

-(NSNumber *)addGroupeToAddressbookWithName:(NSString *)name{
    ABAddressBookRef addressBook = ABAddressBookCreate();
    CFErrorRef error = NULL;
    CFArrayRef sources = ABAddressBookCopyArrayOfAllSources(addressBook);
    CFIndex sourceCount = CFArrayGetCount(sources);
    NSNumber *gId = nil;
    for (CFIndex i = 0 ; i < sourceCount; i++) {
        ABRecordRef currentSource = CFArrayGetValueAtIndex(sources, i);
        CFTypeRef sourceType = ABRecordCopyValue(currentSource, kABSourceTypeProperty);

        BOOL isMatch = kABSourceTypeLocal == [(__bridge NSNumber *)sourceType intValue];
        CFRelease(sourceType);

        if (isMatch) {
            ABRecordRef group = ABGroupCreateInSource(currentSource);//ABGroupCreate();
            ABRecordSetValue(group, kABGroupNameProperty,(__bridge CFStringRef)name, &error);
            ABAddressBookAddRecord(addressBook, group, &error);
            ABAddressBookSave(addressBook,&error);
            gId = [NSNumber numberWithInt:ABRecordGetRecordID(group)];
            CFRelease(group);
            CFRelease(currentSource);
            break;
        }
    }

    CFRelease(sources);
    return gId;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T10:48:56+00:00Added an answer on June 1, 2026 at 10:48 am

    Found that it was because exchange dont know about groups, to save a group it is needed to use the right source, also see : Obtaining Specific ABSource from ABAddressBook in iOS 4+

    new code:

    -(NSNumber *)addGroupeToAddressbookWithName:(NSString *)name{
        ABAddressBookRef addressBook = ABAddressBookCreate();
        CFErrorRef error = NULL;
        CFArrayRef sources = ABAddressBookCopyArrayOfAllSources(addressBook);
        CFIndex sourceCount = CFArrayGetCount(sources);
        NSNumber *gId = nil;
        for (CFIndex i = 0 ; i < sourceCount; i++) {
            ABRecordRef currentSource = CFArrayGetValueAtIndex(sources, i);
            CFTypeRef sourceType = ABRecordCopyValue(currentSource, kABSourceTypeProperty);
    
            BOOL isMatch = kABSourceTypeLocal == [(__bridge NSNumber *)sourceType intValue];
            CFRelease(sourceType);
    
            if (isMatch) {
                ABRecordRef group = ABGroupCreateInSource(currentSource);//ABGroupCreate();
                ABRecordSetValue(group, kABGroupNameProperty,(__bridge CFStringRef)name, &error);
                ABAddressBookAddRecord(addressBook, group, &error);
                ABAddressBookSave(addressBook,&error);
                gId = [NSNumber numberWithInt:ABRecordGetRecordID(group)];
                CFRelease(group);
                CFRelease(currentSource);
                break;
            }
        }
    
        CFRelease(sources);
        return gId;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem: if i run this test in NUnit ,it works Board
NOTE: I have solved the majority of this problem but have run into a
I have run into this problem a few times and I'm not happy with
I have this problem when trying to run hello world program using android SDK.
when i run my application, i get following exception. I have no problem with
When I run this snippet of code: string[] words = new string[] { foo,
Below is the code snippet with comments which describes the problem statement. We have
I have the following snippet of code that I run as part of several
I have problem with Timeout, when I run a command through app, a timeout
I have problem with fancybox. I want to write a function that will run

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.