cowbell / cordova-plugin-geofence

Geofencing plugin for cordova
Apache License 2.0
265 stars 318 forks source link

iOS 8 permissions #121

Closed timwright35 closed 8 years ago

timwright35 commented 8 years ago

On my app I had an issue with permissions not being the right ones and the geofence plugin never telling the user. I add this code, it checks the permissions and popups when it is not given.

func locationManager(manager: CLLocationManager, didChangeAuthorizationStatus status: CLAuthorizationStatus){

        switch CLLocationManager.authorizationStatus() {
        case .AuthorizedAlways: break

        case .NotDetermined:
            registerPermissions()
        case .AuthorizedWhenInUse, .Restricted, .Denied:
        let alertController = UIAlertController(
            title: "Background Location Access Disabled",
            message: "In order to be notified about adorable kittens near you, please open this app's settings and set location access to 'Always'.",
            preferredStyle: .Alert)

        let cancelAction = UIAlertAction(title: "Cancel", style: .Cancel, handler: nil)
        alertController.addAction(cancelAction)

        let openAction = UIAlertAction(title: "Open Settings", style: .Default) { (action) in
            if let url = NSURL(string:UIApplicationOpenSettingsURLString) {
                UIApplication.sharedApplication().openURL(url)
            }
        }
        alertController.addAction(openAction)

        let appDelegate  = UIApplication.sharedApplication().delegate
        appDelegate!.window!?.rootViewController!.presentViewController(alertController, animated: true, completion: nil)
        }
    }
tsubik commented 8 years ago

Yeah, this is a common problem. However, I am not sure if this is plugin role to check these permissions and alert the end user about that or it should be done separately by an application developer. I mean I can imagine if someone is using many different plugins and all these plugins out of nowhere would start popping up with alerts of this kind. It could be disturbing to the end user. Maybe there is somewhere a plugin to check desired permission if not it would be better to design custom separate function like checkPermissions.

timwright35 commented 8 years ago

Yea I can see that, maybe some function in the plugin that sends back an event if permissions are not set at what they need to be and another function that allows the an UI popup like that if called. Thus the person using the plugin as the option to watch for the permission issue and to ask the user in a popup.

tsubik commented 8 years ago

Hey @Tempus35, in the newest version (0.6.0) initialize method should return with an error if any required permission is not granted.