有没有办法检查用户是否允许我的应用程序使用他/她的位置坐标? 我想在他/她按下按钮提交一些信息之前检查一下,如果用户允许,我只会激活此按钮。如何检查userLocation的权限
我的应用程序使用的iOS 6
感谢
有没有办法检查用户是否允许我的应用程序使用他/她的位置坐标? 我想在他/她按下按钮提交一些信息之前检查一下,如果用户允许,我只会激活此按钮。如何检查userLocation的权限
我的应用程序使用的iOS 6
感谢
在你的CLLocationManager
实例的委托,实施
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
方法。如果使用error
参数设置为kCLErrorDenied
调用此方法,那么用户尚未启用位置服务。您还可以实现
- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status
方法 - 当这个回调方法的status
参数不kCLAuthorizationStatusDenied
,那么用户已启用您的应用程序使用他的位置。
我创建了一个组件,以便于iOS上的使用权限。
可在Github上我:
使用的例子使用块:
/*
User can be choose two enum type for request the location authorization:
- AuthorizeRequestTypeAlwaysAuthorization
- AuthorizeRequestTypeWhenInUseAuthorization
*/
[[IOSCheckPermissions globalInstance] checkPermissionAccessForLocation:self.locationManager
authorizeRequestType:AuthorizeRequestTypeWhenInUseAuthorization
successBlock:^{
// SUCCESS ...
} failureBlock:^{
// PERMISSION DENIED ...
}];
谢谢...工作正常! – Vellozo
@Vellozo没问题。 – 2012-10-21 11:25:49