ios 里如何判断当前应用的定位服务是否可用
2015-09-28 14:00
656 查看
如何在某个程序里面判定当前应用程序的定位服务是否可用,其实没有什么简单的方法。
这个[CLLocationManager locationServicesEnabled]检测的是整个iOS系统的位置服务开关,无法检测当前应用是否被关闭,只能通过CLLocationManagerDelegate的locationManager:didFailWithError:方法去检测:
[html] view
plaincopy
- (void)locationManager: (CLLocationManager *)manager
didFailWithError: (NSError *)error {
NSString *errorString;
[manager stopUpdatingLocation];
NSLog(@"Error: %@",[error localizedDescription]);
switch([error code]) {
case kCLErrorDenied:
//Access denied by user
errorString = @"Access to Location Services denied by user";
//Do something...
break;
case kCLErrorLocationUnknown:
//Probably temporary...
errorString = @"Location data unavailable";
//Do something else...
break;
default:
errorString = @"An unknown error has occurred";
break;
}
}
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:errorString delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
[alert show];
[alert release];
}
这个[CLLocationManager locationServicesEnabled]检测的是整个iOS系统的位置服务开关,无法检测当前应用是否被关闭,只能通过CLLocationManagerDelegate的locationManager:didFailWithError:方法去检测:
[html] view
plaincopy
- (void)locationManager: (CLLocationManager *)manager
didFailWithError: (NSError *)error {
NSString *errorString;
[manager stopUpdatingLocation];
NSLog(@"Error: %@",[error localizedDescription]);
switch([error code]) {
case kCLErrorDenied:
//Access denied by user
errorString = @"Access to Location Services denied by user";
//Do something...
break;
case kCLErrorLocationUnknown:
//Probably temporary...
errorString = @"Location data unavailable";
//Do something else...
break;
default:
errorString = @"An unknown error has occurred";
break;
}
}
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:errorString delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
[alert show];
[alert release];
}
相关文章推荐
- iOS8 【xcode6中添加pch全局引用文件】
- 关于真机测试证书的申请
- ios去掉navigationController和tabBarController里的边框黑线
- iostat分析磁盘的IO状况
- iOS9适配
- iOS蓝牙4.0
- IOS开发—对当前屏幕闲置时间计时
- iOS上如何让按钮文本左对齐问题
- Nagios
- 实现iOS全局禁止横屏,但kxmovie全屏横屏播放视频
- iOS页面间传值的方式(Delegate/NSNotification/Block/NSUserDefault/单例)
- ios模拟器不响应电脑键盘解决方法
- iOS - 验证输入的是否是正确的身份证号码和手机号码
- iOS Xcode错误: linker command failed with exit code 1 (use -v to see invocation) 可能错误与处理方法
- 企业级分发-ios9新特性
- iOS开发详解之几种基础动画篇
- iOS 中KVC、KVO、NSNotification、delegate 总结及区别
- iOS/OS X开发:各种工具快到碗里来
- IOS 项目的框架搭建
- iOS中的堆和栈