Reputation: 506
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.
Upvotes: 8
Views: 3225
Reputation: 41
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);
Upvotes: 4