Dan*_*ena 20 objective-c cllocationmanager ios
我有一个带有地图和按钮的视图(比如地图应用程序一次),允许用户在地图上居中和缩放他当前的位置.如果我不能使用locationServicesEnabled方法(总是返回YES),我应该创建一个BOOL属性来检查是否调用了didFailWithError方法并知道我是否可以调用button方法?
谢谢阅读.
编辑:
此代码对我不起作用.我正在使用模拟器.在询问locationServicesEnabled时,我总是得到YES.
// Gets the user present location.
- (IBAction)locateUser:(id)sender {
if([CLLocationManager locationServicesEnabled]) {
CLLocationCoordinate2D coordinate;
coordinate.latitude = self.mapView.userLocation.location.coordinate.latitude;
coordinate.longitude = self.mapView.userLocation.location.coordinate.longitude;
[self zoomCoordinate:coordinate];
} else {
[[[[UIAlertView alloc] initWithTitle:@"Warning." message:@"Location services are disabled."
delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil] autorelease] show];
}
}
Run Code Online (Sandbox Code Playgroud)
Rob*_*bin 99
在"首选项"中,您有两个选项可禁用位置服务.第一个选项是全局开关,用于禁用所有应用程序"[CLLocationManager locationServicesEnabled]"的位置服务.第二个选项允许您禁用某些应用的位置服务,但不能禁用所有应用.
要检查全局是否已禁用以及是否已为您的应用禁用,请执行以下操作:
if([CLLocationManager locationServicesEnabled] &&
[CLLocationManager authorizationStatus] != kCLAuthorizationStatusDenied)
{
...
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
32191 次 |
最近记录: |