1

I have a view that:

  • Creates an observer for UIApplicationDidBecomeActiveNotification with invokes a selector
  • Sequentially asks the user for permissions to: use the camera, location & receiving push notifications.
  • The view has three UIButtons with state depending on each permission state, which navigate the user to settings if permissions for anything were rejected
  • Tapping a button which represents a permission with rejected state navigates the user to settings
  • Once each alert hides, using the observer action, next alert is triggered and all button states are updated to reflect any changes

Once all permissions are granted it pushes next view with the rest of the signup/in flow.

The problem is: on some devices, when running the app from a clean state (app removed and reinstalled), permissions for location & notifications are set to rejected by default, as if the user was presented an alert that was rejected.

I couldn't pinpoint any rational issue behind this, except for leftover settings from some outdated build that don't get deleted when installing a new one. This view seems to be the only place that can possibly trigger these alerts.

Did anyone have a similar issue and can suggest anything?

Cœur
  • 37,241
  • 25
  • 195
  • 267
bartlomiej.n
  • 500
  • 6
  • 19
  • Some of the permissions are stored in iOS for 24 hours, no matter if you removed the app or not. You can force them to re-appear by either launching the app with different bundle ID, or manually resetting all permissions in iOS settings. – 0xNSHuman Mar 30 '17 at 08:54
  • I've tried removing the app, reseting the location & privacy settings, and reinstalling the app again. Same situation – bartlomiej.n Mar 30 '17 at 08:57

1 Answers1

4

I would suggest you to try to check for states of location services and notification services before asking user to use it. Since if user is going to disable these the moment you ask him for permission, he will need to go to the settings and enable it there. You should try to detect if user has disabled location/notification/camera.

For camera use:

func accessToCamera(granted: @escaping (() -> Void)) {
    if UIImagePickerController.isSourceTypeAvailable(.camera) {

        let status = AVCaptureDevice.authorizationStatus(forMediaType: AVMediaTypeAudio)

        if status == .authorized {
            granted()
        } else if status == .denied {
            self.cameraPermissionAlert()
        } else if status == .notDetermined {

            AVCaptureDevice.requestAccess(forMediaType: AVMediaTypeVideo, completionHandler: { (accessAllowed) in
                if accessAllowed {
                    granted()
                } else {
                    self.cameraPermissionAlert()
                }
            })
        } else if status == .restricted {
            self.cameraPermissionAlert()
        }
    } else {
       print("Camera not available on this device")
    }
}

func cameraPermissionAlert() {
    let alert = UIAlertController(title: "Access to camera not available", message: "Please enable access to camera in order to use this feature", preferredStyle: .alert)
    alert.addAction(UIAlertAction(title: "Settings", style: .default, handler: { (action) in
        if let url = URL(string: UIApplicationOpenSettingsURLString) {
            if UIApplication.shared.canOpenURL(url) {
                UIApplication.shared.open(url, options: [:], completionHandler: nil)
            }
        }
    }))

    alert.addAction(UIAlertAction(title: "Cancel", style: .default, handler: nil))
    if let top = UIApplication.topViewController() { // This is extension to UIApplication that finds top view controller and displays it
        top.present(alert, animated: true, completion: nil)
        }
    }

For remote notifications you can use something like this: Determine on iPhone if user has enabled push notifications

And for location services: Check if location services are enabled

In both of these cases you can detect if this is disabled or not by user and present user with alert controller that has open settings functionality.

Community
  • 1
  • 1
Baki
  • 490
  • 4
  • 19