我試圖在我的WatchOS2應用程序中檢索我的當前位置的Lat Lat。 該應用程序已通過身份驗證,iPhone應用程序正常工作。
info.plist:NSLocationWhenInUseUsageDescription
已設置。WatchOS2上的位置始終爲零
我用下面的代碼willActivate()
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyBest
if (CLLocationManager.authorizationStatus() != CLAuthorizationStatus.AuthorizedWhenInUse)
{
locationManager.requestWhenInUseAuthorization()
print("Logon: Location not authorized1")
}
}
locationManager.requestLocation()
在locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation])
我運行這段代碼:
if locationManager.location != nil
{
self.userLat = String(self.locationManager.location!.coordinate.latitude)
self.userLong = String(self.locationManager.location!.coordinate.longitude)
print("Lat\(userLat) Long \(userLong)")
}
else
{
print("An error occurred") <- It always prints this error
}
}
locationManager(manager: CLLocationManager, didFailWithError error: NSError)
不會被調用
你的緯度和LNG檢查時,應用程序在iPhone上的背景是什麼? – RichAppz
@zappiDev這是一個沒有連接到正在運行的手機應用程序的watchos2應用程序?或者你是什麼意思? – Egghead
好吧,我還沒有與原生WatchOS合作過,上次我手錶依賴手機,所以不得不在後臺請求位置服務。 – RichAppz