简体   繁体   English

iOS CoreLocation:如果通过设备设置禁用了位置服务,如何以编程方式处理

[英]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. 请指教。

@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.

相关问题 如何在 iOS 11+ 中以编程方式打开设置 > 隐私 > 定位服务? - how to programmatically open Settings > Privacy > Location Services in iOS 11+? 如何以编程方式处理BLE外设从iOS设备中删除配对 - How to Programmatically Handle BLE Peripheral Removing Pairing from iOS Device iOS 5之前的位置服务和设置 - Location Services and Settings prior to iOS 5 在iOS设备上测试位置服务 - Testing Location Services on iOS Device 如何从corelocation获取旧位置 - how to get old location from corelocation iOS:如何从CoreLocation坐标设置GMSCoordinateBounds? - iOS: How to set GMSCoordinateBounds from CoreLocation Coordinates? iBeacon和WatchO2:CoreLocation是从Watch还是iOS设备运行的? - iBeacon and WatchO2: does CoreLocation run from the Watch or the iOS device? CoreLocation-Geofence事件以启动位置服务 - CoreLocation - Geofence event to start location services 以编程方式在我的 iOS 设备中导入 Wifi 设置 - Import Wifi settings in my iOS device programmatically iOS 7 CoreLocation:在授权位置服务后,区域监控首次失败 - iOS 7 CoreLocation: region monitoring fails on the first time after location services are authorised
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM