开发者

How to get user response when prompted for core location?

When I install my application on the iPhone it asks for the current location with the options "Don't allow" and "Ok" in an alert. How do I find out which option was chosen? I also want to show this option only once. If the user chooses to allow their current location to be found, I want the device to automatically get the location in th开发者_运维百科e background.


If user denied access to Location service then CLLocationManager delegate method didFailWithError: gets called:

- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error{
    if (error.code ==  kCLErrorDenied){
            // User denied access to location service       
    }
}


Your controller should implement the CLLocationManagerDelegate protocol. This defines two methods that you will need to implement:

  1. – locationManager:didUpdateToLocation:fromLocation:
    In this method you put your code to handle location updates.

  2. – locationManager:didFailWithError:
    In this method you put you code to handle the user denying your request, or updates failing.

Once the user allows you to use their location, they won't be prompted again unless they exit the app. There isn't a way to prevent the phone from prompting users each time they start up the app though.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜