jeudi 13 août 2015

How come I can add a group to address book in the iOS simulator, but not the device?

My question is very simple: how come the code below works when I use the simulator, but not the device?

I've used two iPad Airs on a deployment target of 8.2 and 8.4, and an iPad Mini (don't know which one, but relatively new) on 8.2, and none of them are able to add a group.

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

    ABAddressBookRef addressBook;
    bool didSave;
    CFErrorRef error = NULL;

    addressBook = ABAddressBookCreateWithOptions(NULL, &error);

    // If you get some error when trying to add a contact, make sure it's not a permission issue

    ABAddressBookRequestAccessWithCompletion(addressBook, ^(bool granted, CFErrorRef error) {

        if (granted) {

            [self createNewGroup:@"New Group"];
        }

    });

//    [self createNewGroup:@"New Group"];

}

-(void)createNewGroup:(NSString *)groupName
{
    CFErrorRef error = NULL;
    bool didSet, didAdd, didSave;
    ABAddressBookRef addressBook = ABAddressBookCreateWithOptions(NULL, &error);

    if (error) {
        NSLog(@"Error: %@", error);
    }

    ABRecordRef newGroup = ABGroupCreate();

    didSet = ABRecordSetValue(newGroup, kABGroupNameProperty, (__bridge CFTypeRef)(groupName), &error);
    if (!didSet) { NSLog(@"Unresolved error while setting group: %@", error); }

    didAdd = ABAddressBookAddRecord(addressBook, newGroup, &error);
    if (!didAdd) { NSLog(@"Unresolved error while adding group: %@", error); };

    didSave = ABAddressBookSave(addressBook, &error);
    if (!didSave) { NSLog(@"Unresolved error while saving group: %@", error); };

    ABRecordID groupId = ABRecordGetRecordID(newGroup);
//    CFRelease(addressBook);
//    CFRelease(newGroup);
//    CFRelease(error);

}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire