有沒有辦法檢查用戶是否允許我的應用程序使用他/她的位置座標? 我想在他/她按下按鈕提交一些信息之前檢查一下,如果用戶允許,我只會激活此按鈕。如何檢查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