Using your primary location in Apple WatchKit

I am currently developing an extension for an apple watch. Does anyone know if the current location of the iPhone or Watch is provided? I can not find information about this, and I need to draw a compass indicating what the clock is pointing to.

+3
source share
3 answers

To do what you want, you do not need CoreLocation, you need a magnetometer.

AFAIK Apple Watch does not have an integrated device.

The sensors that he has ...

  • Accelerometer
  • gyroscope
  • Heart rate sensor
  • Barometer

No magnetometer, though.

+3
source

According to Apple Dev Documentation:

The best solution for any long-term task is to let your iOS application complete the task. For example, instead of starting location services in your WatchKit extension, launch it in your iOS app. An iOS application can collect the necessary data and put it in a common application group so that your extension can access it later. Use the openParentApplication: reply: method to start tasks and receive a response or use a shared group container to exchange data between your iOS application and the WatchKit extension. For information on how to handle the connection between your iOS application and the WatchKit extension, see Direct communication with your iOS mobile application.

PS I am working on a similar application.

0
source

You cannot use CoreLocation from the watchkit extension. However, you can use the api to open the parent application (in the background) and ask the parent api for information. Api is really nice because you can use it with an answer so that you can easily return information:

+ (BOOL)openParentApplication:(NSDictionary *)userInfo reply:(void(^)(NSDictionary *replyInfo, NSError *error)) reply; // launches containing iOS application on the phone 
-1
source

Source: https://habr.com/ru/post/981040/


All Articles