如何在iOS 7中检查特定应用程序是否启用了位置服务?

5

我想检查我的应用程序的位置服务是否已经打开或关闭,因为当我将位置服务打开应用程序服务关闭时,我该如何通过代码进行检查。

请帮忙解决我的问题。

提前致谢。

2个回答

15

对于那些试图在Swift中实现此操作的人。

if CLLocationManager.locationServicesEnabled() {
    switch(CLLocationManager.authorizationStatus()) {
    case .NotDetermined, .Restricted, .Denied:
        println("No access")
    case .AuthorizedAlways, .AuthorizedWhenInUse:
        println("Access")
    default:
        println("...")
    }
} else {
    println("Location services are not enabled")
}

太棒了,继续保持 :) - Mr. Bean
完美的答案。非常感谢。 - Badrinath

4
在locationManager:didFailWithError:中,添加以下内容:
-(void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error{


    if([CLLocationManager locationServicesEnabled])
    {
        NSLog(@"Enabled");

        if([CLLocationManager authorizationStatus]==kCLAuthorizationStatusDenied)
        {
             NSLog(@"Permission Denied");
        }
    }
 }

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接