当前位置许可对话框消失得太快 [英] Current location permission dialog disappears too quickly
问题描述
我的应用程序获取用户的位置,获取坐标,并提供与目的地或来源的距离。所有这些可能的目的地都显示在表格视图中,因此我在填充表格的同时获得用户坐标。唯一的问题是,出现要求用户位置的警报视图然后消失得太快就无法点击它!
My app takes the user's location, gets the co-ordinates , and provides a distance to or from their destination or origin. All these possible destinations are shown in a table view, so I'm getting the users co-ordinates at the same time as populating the table. The only thing is, the alert view that asks for the users location appears then disappears so quickly it's impossible to click it!
有什么方法可以手动显示此警报该应用程序首先加载?我尝试在应用程序加载时获取用户的位置以尝试强制显示警报,但这不起作用。
Is there any way to manually present this alert when the app first loads? I tried getting the user's location when the app loads up to try and force the alert to show, but that didn't work.
推荐答案
虽然难以追踪,但解决方案非常简单。
While difficult to track down, the solution for this is quite simple.
通过大量试验和错误我发现当你尝试时会弹出位置访问对话框要首次访问应用程序中的任何位置服务,如果在用户响应之前释放 CLLocationManager
对象,则对话框将自行消失(无需任何用户交互)对话框。
Through much trial and error I found out that while the location access dialog pops up when you try to access any location services in the app for the first time, the dialog disappears on its own (without any user interaction) if the CLLocationManager
object is released before the user responds to the dialog.
我在 viewDidLoad $ c $中创建了一个
CLLocationManager
实例c>方法。由于这是该方法的本地实例,因此该方法在完成执行后由ARC释放。实例一释放,对话框就消失了。解决方案相当简单。将 CLLocationManager
实例从方法级变量更改为类级实例变量。现在只有在卸载类时才会释放 CLLocationManager
实例。
I was creating a CLLocationManager
instance in my viewDidLoad
method. Since this was a local instance to the method, the instance was released by ARC after the method completed executing. As soon as the instance was released, the dialog disappeared. The solution was rather simple. Change the CLLocationManager
instance from being a method-level variable to be a class-level instance variable. Now the CLLocationManager
instance is only released once the class is unloaded.
这篇关于当前位置许可对话框消失得太快的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!