[英]iOS CoreLocation: How to handle programmatically if location services are disabled from device settings
I am trying to get the geolocation of the iOS device. 我正在尝试获取iOS设备的地理位置。 I am able to get the coordinates of the present location using CoreLocation framework. 我可以使用CoreLocation框架获取当前位置的坐标。
But the problem is I have to handle the scenario when location services has been disabled from device settings. 但是问题是我必须处理从设备设置中禁用位置服务的情况。 In that case, I have to redirect the user to settings from within my app as per the requirement. 在这种情况下,我必须根据要求将用户重定向到我的应用程序中的设置。
I know that I can do this using the below scheme prior to iOS 5.1 我知道我可以在iOS 5.1之前使用以下方案执行此操作
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs://"]]; [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@“ prefs://”]];
But, how to handle this in this newer releases. 但是,如何在此较新版本中处理此问题。 I am stuck with this since a long time and no solution yet. 我已经坚持了很长时间,目前还没有解决方案。 Please advise. 请指教。
You should call: [CLLocationManager locationServicesEnabled] 您应该致电:[CLLocationManager locationServicesEnabled]
As it states here: 如此处所示:
http://developer.apple.com/library/ios/#documentation/CoreLocation/Reference/CLLocationManager_Class/CLLocationManager/CLLocationManager.html http://developer.apple.com/library/ios/#documentation/CoreLocation/Reference/CLLocationManager_Class/CLLocationManager/CLLocationManager.html
@Rashmi - You might be getting some trouble some where else. @Rashmi-在其他地方可能会遇到麻烦。
CoreLocation Framework automatically detects if the Location Settings are disabled from the Device via generating an alert and take you automatically to the device settings.I had verified this in iOS7, iOS6 devices. CoreLocation Framework会通过生成警报自动检测是否从设备禁用了位置设置,并自动将您带到设备设置。我已在iOS7,iOS6设备中对此进行了验证。
Moreover, I Googled and found that this is the only way to open setting from the app and that matches with you have written. 而且,我在Google上搜索后发现,这是从应用程序打开设置的唯一方法,并且与您编写的内容相匹配。
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs://"]];
You can also follow this URL for reference Open Device Settings from the app 您也可以按照此URL进行参考,以从应用程序中打开设备设置
For Core Location, You can see this demo CoreLocation 对于核心位置,您可以查看此演示CoreLocation
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.