2012-10-21 35 views
0

有没有办法检查用户是否允许我的应用程序使用他/她的位置坐标? 我想在他/她按下按钮提交一些信息之前检查一下,如果用户允许,我只会激活此按钮。如何检查userLocation的权限

我的应用程序使用的iOS 6

感谢

回答

4

在你的CLLocationManager实例的委托,实施

- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error 

方法。如果使用error参数设置为kCLErrorDenied调用此方法,那么用户尚未启用位置服务。您还可以实现

- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status 

方法 - 当这个回调方法的status参数不kCLAuthorizationStatusDenied,那么用户已启用您的应用程序使用他的位置。

Documentation here.

+1

谢谢...工作正常! – Vellozo

+0

@Vellozo没问题。 – 2012-10-21 11:25:49

1

我创建了一个组件,以便于iOS上的使用权限。

可在Github上我:

enter image description here

使用的例子使用块:

/* 
    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 ... 
    }];