OGeek|极客世界-中国程序员成长平台

标题: ios - 当用户下次点击不允许时如何显示用户位置? [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 10:58
标题: ios - 当用户下次点击不允许时如何显示用户位置?

在我的应用程序中,我想在使用 MKMapKitUIViewController 之一中显示用户位置。因此,当用户选择此 View Controller 时,将询问他们是否允许或不允许。如果用户选择允许,那么一切正常。如果他们选择不允许,那么用户将不再被询问是否允许。

其实我想要的是,当用户第一次使用我的应用程序时选择不允许,他们应该被要求再次选择允许或不允许他们下次使用该应用程序。那么我该如何实现呢?当用户选择允许选择时间(他们第一次单击不允许)时,我的应用程序会显示用户位置。

即使在一些 S.O 问题中,许多人也建议用户在打开应用程序时会被提升为允许或不允许警报。但对我来说,它要求第一次使用应用程序。

请分享您的想法。谢谢你。



Best Answer-推荐答案


如果用户第一次为您的应用关闭了位置服务,那么您每次尝试获取他们的位置时都会在您的应用中知道。您可以检查用户是否已授予您读取其位置的权限。如果他们没有,系统会再次提示他们为您的应用启用位置服务。

引用 Apple 的文档 (found here)

it is recommended that you always call the locationServicesEnabled class method of CLLocationManager before attempting to start either the standard or significant-change location services. (In iOS 3.x and earlier, check the value of the locationServicesEnabled property instead.) If this class method returns YES, you can start location services as planned. If it returns NO and you attempt to start location services anyway, the system prompts the user to confirm whether location services should be reenabled. Given that location services are very likely to be disabled on purpose, the user might not welcome this prompt.

关于ios - 当用户下次点击不允许时如何显示用户位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16580384/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4