8

In my app i am getting contact information directly buy doing this ...

ABAddressBookRef m_addressbook = ABAddressBookCreate();

CFArrayRef allPeople = ABAddressBookCopyArrayOfAllPeople(m_addressbook);

CFIndex nPeople = ABAddressBookGetPersonCount(m_addressbook);

for (int i=0;i < nPeople;i++)
{
    ABRecordRef ref = CFArrayGetValueAtIndex(allPeople,i);
    CFStringRef company,firstName,lastName;

     firstName = ABRecordCopyValue(ref, kABPersonFirstNameProperty);
     lastName  = ABRecordCopyValue(ref, kABPersonLastNameProperty);
     company = ABRecordCopyValue(ref, kABPersonOrganizationProperty);
}

So, i need to check first Whether this is ON/OFF Settings --> Privacy --> Contacts ON/OFF for my app.

For this I am doing this :

__block BOOL accessGranted = NO;


float sysver = [[[UIDevice currentDevice]systemVersion]floatValue];

if(sysver>=6) {
    ABAddressBookRef addressBook = ABAddressBookCreate();

    if (ABAddressBookRequestAccessWithCompletion != NULL) {  
        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 { 
         accessGranted = YES;
     }
} else {
    accessGranted = YES;
}

if(accessGranted) 
{
    // doing my stuff and moving on
} else {
    // please make Settings --> Privacy --> Contacts  my app.  ON for accessing contacts.
}

My issues is , at very first time after installing app on device , app asked me to "Don't allow"/ "Ok" alert for contact grant access. I clicked on Ok but Settings --> Privacy --> Contacts for my app was OFF so again got alert to make it ON, "Settings" "Ok" so selected Settings , and i made it ON ,, once i made it ON app get SIGKILL nothing to console.

and later whenever i changed Privacy setting to OFF to ON app getting crash at background . i get SIGKILL nothing to console.

Thanks In Advance.

Moxy
  • 4,162
  • 2
  • 30
  • 49
Rohit Wankhede
  • 506
  • 5
  • 15
  • I think it's normal behavior. if you toggle the contacts privacy setting of an app, iOS will kill that app. – Moxy Oct 14 '13 at 13:11
  • Moxy is right, this is expected behavior. Aditya, check this question for links to apple docs on app behavior when privacy settings changed - http://stackoverflow.com/questions/12522574/toggling-privacy-settings-will-kill-the-app – Kedar Oct 14 '13 at 14:13
  • @moxy and kedar , thanks , but at very first run , app behave abnormally with above code ,, as while waiting for permissions app goes for next step. – Rohit Wankhede Oct 14 '13 at 14:32
  • @RohitWankhede, When your app is running in iDevice or Simulator & you make changes about any kind of privacy settings for that app. iOS will kill that app with `SIGABART`. It's very much normal behaviour. Just start the app again. – Akshit Zaveri Oct 14 '13 at 14:49
  • @AkshitZaveri Moxy Kedar Thanks, Actually, On very first run, i got this behavior. at if(sysver>=6){--} I get an alert for access permissions for contact then get second alert that make it ON to access Contacts.Alert "Settings" button. then back to app its running(not kill) but all functionality get disturbed. and problem is, i am not able to reproduce this scenario. I have deleted app, profile,restarted device, installing app again but not getting this scenario, it will be helpful if you help me to re-produce this scenario. should i have to this with new code? – Rohit Wankhede Oct 15 '13 at 07:07
  • If you want to re-produce that scenario than you have to change the `Bundle identifier` from `Target` settings of project. @RohitWankhede – Akshit Zaveri Oct 15 '13 at 07:09
  • @RohitWankhede, iOS saves your used bundle list & remembers the privacy settings for them. So if you use same `bundle identifier` again it will just get settings from saved data. – Akshit Zaveri Oct 15 '13 at 07:10

1 Answers1

4

There is another post with a similar issue found here.

It is intended OS functionality that each application is terminated when Privacy settings are changed. This is to ensure that each application abides by the users privacy and doesn't continue to use any cached data after the privacy settings are altered.

Also please note that your suggested code

float sysver = [[[UIDevice currentDevice]systemVersion]floatValue];
    if(sysver>=6) {

is not recommended by Apple and there is a better, more official approach such as using the Foundation #define values i.e.

BOOL isiOS6OrMoreRecent = NSFoundationVersionNumber >= NSFoundationVersionNumber_iOS_6_0 ? YES : NO;

However it is very bad practice to use iOS versions in order to determine available functionality, instead check for the feature itself independently of the OS version (Address Book Code here, such as:

if (ABAddressBookRequestAccessWithCompletion) { // if in iOS 6
    // Request authorization to Address Book
    ABAddressBookRef addressBookRef = ABAddressBookCreateWithOptions(NULL, NULL);
Community
  • 1
  • 1