0

I can say that I have no idea how/why this happened.

I have a watchOS 2 app I am working on. I've been working on it all day and it uses core location. It's been getting current location just fine. I need the lat/long in order to make a network call that takes those as parameters.

Anyway, I was field testing and noticed my app crashed. Over and over it was crashing on my watch.

Went home to debug and I noticed that the URL had nil values for the coordinates. Weird, it was working all day every day for months. I haven't made any changes to the Core Location code.

I am using

func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation])

in order to detect when to make a network call. I can only make the network call IF and ONLY IF I have those coordinates. I look at the locations parameter to see if it is greater than 0 and then I get the lat/long of the last object in it. I've also checked the values in the locationManager instance I have running.

Anyway, these values are nil! How can these values be nil if the function locationManager:didUpdateWithLocations: was called?

I'm very confused because it just happened in the middle of field testing. It was working all day when I was out and about then it just stopped. Other apps like the Maps app on my Apple Watch work okay. Also, all the location permissions are on. I even deleted the app on my iOS device and my watch to start with a fresh app. That didn't fix the problem.

I am only calling the function to stop updating location AFTER I get a successful response from the web server which only kicks off if I get legitimate values from Core Location for lat/long.

Any ideas?

Mario A Guzman
  • 3,483
  • 4
  • 27
  • 36

2 Answers2

0

With watchOS 1 the watch app needed to ask the phone app to determine location.

With watchOS 2 the watch app can call requestLocation one time. This other answer explains it.

Community
  • 1
  • 1
progrmr
  • 75,956
  • 16
  • 112
  • 147
  • I see. But Xcode allows me to write identical code to get current location using CLLocationManager as I would on an iOS project. It doesn't warn me that the Watch does not have GPS built in. Further more, it DOES grab location from time to time. I see the coordinates printout in the console when I test the Watch App. This makes me think I should be able to request location from the Watch. Perhaps it doest the communication from the iPhone for me? – Mario A Guzman Oct 26 '15 at 23:00
  • yes, that was exactly what I followed. It grabs one location (which is perfect) but it then stops updating location or it won't update if i go somewhere else. It either reports nil or remains the same as before. – Mario A Guzman Oct 27 '15 at 16:27
0

I had the same Problem, because I implemented the CLLocationManagerDelegate in my ExtensionDelegate. The same implementation inside a WKInterfaceController works perfectly well.

Blank
  • 4,872
  • 2
  • 28
  • 25