2

I have developed the application to fetch the contacts from the address book database. For this the implemented code is code fine for the iOS version 6.0, but it crashes on iOS 6.1.3.

The code which I have implemented to fetch the contacts from the address book database:

ABAddressBookRef addressBook;

if ([self isABAddressBookCreateWithOptionsAvailable]) {
    // iOS 6
    CFErrorRef error = nil;
    addressBook = ABAddressBookCreateWithOptions(NULL,&error);
    ABAddressBookRequestAccessWithCompletion(addressBook, ^(bool granted, CFErrorRef error) { });
    ABAddressBookRevert(addressBook);
} else {
    // iOS 4/5
    addressBook = ABAddressBookCreate();
}

-(BOOL)isABAddressBookCreateWithOptionsAvailable
{
    return &ABAddressBookCreateWithOptions != NULL;
}

Please help me with this.

M Vignesh
  • 1,586
  • 2
  • 18
  • 55
  • How about adding some details about the crash? E.g. a symbolicated crash report so we know what the problem is. I guess you don't want this to be a riddle, right? :) – Kerni Apr 02 '13 at 14:11
  • While getting the data from the DB, it always return null for the ios Version 6.1.3. – M Vignesh Apr 03 '13 at 07:47

1 Answers1

0

i'm not sure that this code will crash or not but i think this should be run in iOS 6.1.3

-(IBAction)btnShowContactClicked {
//ABAddressBookRef addressBook = ABAddressBookCreate();
CFErrorRef *aberror = NULL;
addressBook = ABAddressBookCreateWithOptions(NULL, aberror);
__block BOOL accessGranted = NO;

if (ABAddressBookRequestAccessWithCompletion != NULL) { // we're on iOS 6
    dispatch_semaphore_t sema = dispatch_semaphore_create(0);

    ABAddressBookRequestAccessWithCompletion(addressBook, ^(bool granted, CFErrorRef error) {
        accessGranted = granted;
        dispatch_semaphore_signal(sema);
    });

    dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER);
    dispatch_release(sema);
}
else { // we're on iOS 5 or older
    accessGranted = YES;
}

if (accessGranted) {
    ABPeoplePickerNavigationController *picker = [[ABPeoplePickerNavigationController  alloc] init];
    picker.peoplePickerDelegate = self;
    [self presentViewController:picker animated:YES completion:nil];
    //  //[self.navigationController presentModalViewController:picker animated:YES];
    [picker release];
}
}
kagmanoj
  • 5,038
  • 5
  • 19
  • 21