0

I'm updating my app to use CNContacts instead of AB. I've noticed that I am not getting prompted for granting permission to my Contacts. In the below switch, it is correctly telling me I am denied access - but then it doesn't prompt me to give it access. Furthermore, it just displays the picker and even stores the chosen properties into the tableview I am populating...

Is it not required to get permission to grab phone numbers or emails out of Contacts? I am confused why my code seems to be working if I am ".Denied"

//This code is called when you hit the "add a contact" button on my UI
switch CNContactStore.authorizationStatusForEntityType(.Contacts){
    case .Authorized:
        print("Already authorized")
        presentPicker()
        /* Access the address book */
    case .Denied:
        print("Denied access to address book")

        store.requestAccessForEntityType(.Contacts){succeeded, err in
            guard err == nil && succeeded else{

                return
            }
            self.presentPicker()
        }


    case .NotDetermined:

        store.requestAccessForEntityType(.Contacts){succeeded, err in
            guard err == nil && succeeded else{

                return
            }
        self.presentPicker()
        }
    default:
        print("Not handled")
    }
Charlie
  • 1,279
  • 2
  • 12
  • 28

1 Answers1

1

You do not need authorization to use CNContactsPickerViewController. It is "out of process"; it just works. In effect, it is the Contacts app sitting inside your app — and the user doesn't need permission to use the Contacts app.

matt
  • 515,959
  • 87
  • 875
  • 1,141
  • This is just... I'm so happy. I was so confused. Thanks!! I thought since I was using the stored values in the phone and email fields it would require a prompt... didn't AB require it!? – Charlie Oct 05 '15 at 18:25
  • 2
    It's kind of amazing. You can get massive amounts of CNContact info this way with no authorization at all. Apple has a funny idea of what authorization is about... But I guess the idea is that if the user didn't want to you to have any info, the user could just cancel without tapping any contacts. – matt Oct 05 '15 at 18:26
  • Makes a lot of sense, just seems so open and easy to use it makes me suspicious. Haha. – Charlie Oct 05 '15 at 18:27
  • Actually AB didn't require authorization for this either (starting in IOS 8). So this is not new. – matt Oct 05 '15 at 18:28
  • Interesting. Well, thank you so much! Waiting to be able to select your answer as valid since there is a wait period. – Charlie Oct 05 '15 at 18:29
  • Understood. Glad you no longer think you're going insane. :) – matt Oct 05 '15 at 18:39
  • @matt Not sure if you have noticed this but on ios9.x contacts prompts user for permission only once across installation. e.g It prompts user the first time I launch my app, I then delete and reinstall app, it somehow saves my preference from the last time. I can verify this by going to settings app. This is not the case with gallery, camera and location access. – B K Feb 14 '17 at 10:48
  • @B K: all of the user data sources should be consistently protected. Deleting the app should make them all unset, and then a new install should challenge anew. It is possible that this didn't work well and Apple fixed in the last 3 years, but I've got an apps that do camera, photo, and contacts, and the uninstall;re-install seems to work as expected, circa iOS 11+ – benc Aug 05 '20 at 01:19