Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS App gets crash in background as changed Settings->Privacy->Contacts My App ON/OFF

Tags:

ios

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.

like image 632
Rohit Wankhede Avatar asked Oct 14 '13 12:10

Rohit Wankhede


People also ask

Why do my apps keep closing in the background iPhone?

Random and frequent app crashes in mobile devices usually denote a memory issue like when the device is running low on storage. Other performance issues including symptoms of sluggishness, unresponsiveness and random restarts are also likely to transpire in this case.

How do I turn off my Privacy settings on my iPhone?

The App Privacy Report shows you how apps are using the permissions you granted them and shows you their network activity. To turn off the report and delete its data, go to Settings > Privacy & Security > App Privacy Report, then tap Turn Off App Privacy Report.

What factors can cause an app to crash?

An Android app crashes whenever there's an unexpected exit caused by an unhandled exception or signal. An app that is written using Java or Kotlin crashes if it throws an unhandled exception, represented by the Throwable class.

Why do apps need access to my contacts?

Contacts It's not your data to give. Some apps ask for access to your contacts to make sharing and finding friends easy. For example, a messaging app like Telegram will check to see which of your friends also use it.


1 Answers

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);
like image 122
Matt Harding Avatar answered Nov 15 '22 04:11

Matt Harding