【问题标题】:Location in Simulator doesn't work. I get nil latitude and nil longitude模拟器中的位置不起作用。我得到零纬度和零经度
【发布时间】:2015-11-29 19:39:35
【问题描述】:

但是当使用真实设备时,我会获得正确的坐标。

在模拟器中,我去 debug-Location-Custom Location 或 Apple 但我总是获得 nil 值。

在真实设备中,两个人可以使用该应用程序,即没有 nil 值,但有三分之一的人由于坐标值为零而崩溃。

在偏好中,我们都已经激活了定位服务。

【问题讨论】:

  • 发布位置代码以提供更多信息
  • @user2893289 什么意思?
  • 您应该在问题中包含MCVE。不是您的所有代码,而是让我们重现您描述的问题的最小量。

标签: swift location cllocationmanager simulator


【解决方案1】:

有时模拟器只是想用你的时间玩游戏:),所以完全重置就可以了。

但是,为了防止您的应用从规则设备或模拟器中崩溃,您应该确保您拥有对 gps 的完全访问权限。所以你应该使用 didChangeAuthorizationStatus 方法。

func locationManager(manager: CLLocationManager, didChangeAuthorizationStatus status: CLAuthorizationStatus)
    {
        if status == CLAuthorizationStatus.Restricted
        {
           print(" Access Restricted \n")
        }
        else if status == CLAuthorizationStatus.Denied
        {
            print(" Access Denied \n")

        }
        else if status == CLAuthorizationStatus.AuthorizedAlways
        {
            self.MyLocationManager.startUpdatingLocation()  //<---- 
            print(" Access Granted \n")
        }
    }

如您所见,当您拥有AuthorizedAlways 时,您想启动您的 GPS。

【讨论】:

  • 我觉得模拟器只是想和我玩,这是我第一个想到的。但是有一个朋友在那个时候崩溃了,但不是我和我的朋友,只有他,此刻......
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-03-13
  • 2011-03-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-05-22
相关资源
最近更新 更多