开发者

check if a user allows the app to use their location

开发者 https://www.devze.com 2022-12-14 04:40 出处:网络
The first time the app tries to get the users location they are prompted with \"Would like to use your current location\" and they can hit Don\'t allow or ok.Is there any way to find out if the user h

The first time the app tries to get the users location they are prompted with "Would like to use your current location" and they can hit Don't allow or ok. Is there any way to find out if the user has hit ok or don't allow? I'm trying to have the MKMapView show the users current location but I would like to take different actions based on the users selection.

Normally you would think there would be a delegat开发者_如何学Goe to get this information but there doesn't seem to be.

Thanks in advance for your help.


Your first call to get the user's location will fail with an error which tells you the user has denied location services. Your CLLocationManagerDelegate method didFailWithError will be called, as below. (The constants are defined in CLError.h)

- (void)locationManager:(CLLocationManager*)aManager didFailWithError:(NSError*)anError
{
    switch([anError code])
    {
    case kCLErrorLocationUnknown: // location is currently unknown, but CL will keep trying
    break;

    case kCLErrorDenied: // CL access has been denied (eg, user declined location use)
    message = @"Sorry, flook has to know your location in order to work. You'll be able to see some cards but not find them nearby";
    break;

    case kCLErrorNetwork: // general, network-related error
    message = @"Flook can't find you - please check your network connection or that you are not in airplane mode";
    }
}
0

精彩评论

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

关注公众号