-->

Can I access healthkit data from iWatch extension?

2019-08-13 02:09发布

问题:

I am making a iWatch app where I need to show data from healthkit. is it possible to access healthkit APIs from iWatch extension?

回答1:

No. It's mentioned specifically in the HealthKit Framework Reference:

"You cannot access HealthKit from extensions (like the Today view) or from a WatchKit app."

What you can do is call openParentApplication:reply: to talk to the iPhone app itself and retrieve that data. Search around for that method name and you'll find some examples on how to call it and get data back to the Watch from it.


UPDATE: As others have mentioned below, this has changed for watchOS 2. The documentation has not been updated yet, but check out the WWDC 2015 videos for HealthKit and the Watch for some snippets of code you can use with the Xcode 7 beta.



回答2:

Yes, in watchOS 2 you will be able to.



回答3:

Yes, it's possible on watchOS 2.

However, it's a bit confusing, because it's still mentioned in the HealthKit Framework Reference for watchOS

You cannot access HealthKit from extensions (like the Today view) or from a WatchKit app.

Do not care about this.

Follow a few steps below.

  1. Follow Setting Up HealthKit in the reference, you are now ready to access
  2. Follow Accessing HealthKit Data, then you will be able to access

Make sure your application is running on watchOS 2.

Please see the reference for more detail.