Programmatically changing privacy settings on iOS

Over the past day I have been trying to finalize a view controller that accesses the contacts in a user's address book. I have been signing up with various apps and going through their signup flows where they ask you for access to your address book.

There are 2 different ways that these apps handle address book access:

  1. The app wants access to contacts, so they show a UIAlertView window that says something like this: "We need to access your address book. You can enable this by going to Settings > Privacy > Contacts > Turn on for App Name.

  2. The app wants access to contacts, so they show a UIAlertView window that says something like this: "We need to access your contacts so we can find your friends"

What's different though about option 2 is that in the UIAlertView window, they actually have 2 buttons for "Don't Allow" and "OK".

I was under the impression that if you actually press "OK" it will allow access to your contacts, and if you press "Don't Allow" it will block the app from accessing your contacts.

However, even if I press "OK" in these apps, it doesn't even change the privacy settings. Pressing "Don't Allow" doesn't change anything either.

So, are these apps just choosing to show "OK" and "Don't Allow" for whatever reason, despite the fact that they don't even work or have any functionality at all? I assumed that there was a way to programmatically change the privacy settings, and that by pressing the "OK" button a method was being called that actually did something.

I am using iOS 7.0.4 on an iPhone 4S and I just recently started developing for iOS so I only have experience with iOS 7.

I just don't understand what's really possible and why I am experiencing the behavior above.

If someone could clear this up for me I would really appreciate it.

Answers


The first one does not change any thing because it is an instruction that tells you how to enable the related privacy settings in the settings app. You have to go to the settings app and navigate to the right view and change the privacy setting by yourself

It is possible to access users' contacts on iOS devices. And you do not have to make up a customized message to tell users why you need the permission. Apple will prompt the user with a system alertView. I think the second one was supposed to bring up the system alertView when you pressed "ok".

You have to put the following code before accessing users' contacts. Somewhere in applicationDidFinishLaunching should be good.

ABAddressBookRef addressBookRef = ABAddressBookCreateWithOptions(NULL, NULL);

  if (ABAddressBookGetAuthorizationStatus() == kABAuthorizationStatusNotDetermined) {
    ABAddressBookRequestAccessWithCompletion(addressBookRef, ^(bool granted, CFErrorRef error) {
      if (granted) {
          // access has been granted.
      } else {
          // User denied access
      }
    });
  }
  else if (ABAddressBookGetAuthorizationStatus() == kABAuthorizationStatusAuthorized) {
    // The user has previously given access
  }
  else {
    // The user has previously denied access

  }

Short answer is that there is no (Apple authorized) way to change the privacy settings programmatically after the user has chosen the address book access option the first time the app is run. Since both of the options you outlined sound like they're developer generated, they can really mean and do anything.


Need Your Help

Using Auto-Layout in custom UITableViewCell

ios iphone autolayout storyboard uitableview

I'm working with a custom UIableViewCell that has four UILabels inside of it.

Execute liquibase update in production environment

console production liquibase

I have a Java Maven project. I'm using liquibase to update DB.