core-locationwatchosclockkit

Best way to get Core Location data from an Apple Watch Complication?


What is the prescribed method of figuring out a user's latitude and longitude from the complication?

I've tried instantiating a location manager inside the complication controller, and requesting the location, both using requestLocation, and startUpdatingLocation. Neither responds with an update.

I am using watchOS 4.0 and iOS 9.3.

Any help is greatly appreciated.


Solution

  • A few important points:

    1. Don't do any computation or async request in your Complication Controller, you will eat up your complication update budget for a day very quickly, plus OS will suspend the process after a few seconds.

    2. You can use Core Location in your Extension Delegate either in foreground (no restrictions) or in the background. If you want to use it in the background, you need to set UIBackgroundModes to location in your WatchKit Extension's Info.plist AND your location manager's allowBackgroundLocationUpdates property to true. Don't forget to set it to false when you don't need constant location updates. For instance, if you need to request the location once in the background, turn that property off once you receive the location fix.

    3. You can only update your complication so many times during the day (Apple doesn't publish the exact number). You can expect to be able to update it at least 4-6 times an hour, possibly more, but definitely not every minute. So you can forget about displaying any real-time data on your complication.