Using Core Location in Apple WatchKit

后端 未结 3 819
半阙折子戏
半阙折子戏 2021-01-06 06:09

I\'m currently developing an apple watch extension. Anybody knows if the current location is provided by iPhone or Watch itself? I can\'t find any information about this and

相关标签:
3条回答
  • 2021-01-06 06:48

    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
    
    0 讨论(0)
  • 2021-01-06 06:53

    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.

    0 讨论(0)
  • 2021-01-06 06:53

    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.

    0 讨论(0)
提交回复
热议问题