Can I access healthkit data from iWatch extension?

2019-08-13 02:16发布

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

3条回答
孤傲高冷的网名
2楼-- · 2019-08-13 02:43

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.

查看更多
放我归山
3楼-- · 2019-08-13 02:50

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.

查看更多
我命由我不由天
4楼-- · 2019-08-13 02:56

Yes, in watchOS 2 you will be able to.

查看更多
登录 后发表回答