2012-10-21 32 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 ... 
    }];