Using Core Location in Apple WatchKit

混江龙づ霸主 提交于 2019-11-30 22:13:24

In order to do what you want you don't need CoreLocation you just need a magnetometer.

AFAIK the Apple Watch doesn't have one built in.

The sensors it has are...

  • Accelerometer
  • Gyroscope
  • Heart rate sensor
  • Barometer

No magnetometer though.

According to Apple's Dev Documentation:

The best solution for performing any long-running tasks is to let your iOS app perform the task instead. For example, instead of starting location services in your WatchKit extension, start it in your iOS app. Your iOS app can gather the needed data and put it in a shared app group so that your extension can access it later. Use the openParentApplication:reply: method to initiate tasks and receive a reply or use a shared group container to communicate details between your iOS app and WatchKit extension. For information about how to handle communication between your iOS app and WatchKit extension, see Communicating Directly with Your Containing iOS App.

P.S. I am working on similar app.

Paul Yorke

You can't use CoreLocation from the watchkit extension. You can however use an api to open the parent app (in the background) and ask your parent api for the information. The api is really nice because you can use it with a reply so that you can easily get the information back:

+ (BOOL)openParentApplication:(NSDictionary *)userInfo reply:(void(^)(NSDictionary *replyInfo, NSError *error)) reply;    // launches containing iOS application on the phone
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!