CLLocationManager AuthorizationStatus callback?

后端 未结 6 1828
天命终不由人
天命终不由人 2021-02-01 02:38

In my app I have a tab called \"Discover\". The Discover tab will use the users current location to find \"stuff\" near them. Instead of presenting the user with a generic Autho

6条回答
  •  后悔当初
    2021-02-01 03:25

    You can use the locationManager:didChangeAuthorizationStatus: CLLocationManagerDelegate method as a "callback" of sorts.

    - (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status {
        if (status == kCLAuthorizationStatusDenied) {
            // The user denied authorization
        }
        else if (status == kCLAuthorizationStatusAuthorized) {
            // The user accepted authorization
        }
    }
    

    And in Swift (update suggested by user Michael Marvick, but rejected for some reason...):

    func locationManager(manager: CLLocationManager, didChangeAuthorizationStatus status: CLAuthorizationStatus) {
        if (status == CLAuthorizationStatus.denied) {
            // The user denied authorization
        } else if (status == CLAuthorizationStatus.authorizedAlways) {
            // The user accepted authorization
        } 
    }
    

提交回复
热议问题