Accessing data from HealthKit with Swift

一曲冷凌霜 提交于 2021-02-11 15:16:53

问题


I'm a complete noob at Swift (and Xcode), as a matter of fact, the only programming language I (somewhat) know is Javascript.

I'm trying to make a Swift SpriteKit game, and I would like to access the number of calories burned in HealthKit.

The idea is that my game will provide more points the more calories you burn using other apps like Endomondo. My app does not actually track anything, I would just like to access other data left by other apps in the Health App.

Is this even possible? (I'm running the latest version of everything, from Mac OS X to Xcode)


回答1:


Certainly. I don't think there is anything technically preventing you from making calls to the HealthKit APIs in your game. In fact, you're fairly free to mix and match the use of any public frameworks provided on iOS.

One thing to keep in mind is privacy and disclosure of the use of health data. The user will have to explicitly grant your app permission to see data.

HealthKit is a really rich API with lots of ways to access lots of different kinds of data, and you're really only interested in a small part right now, so a quick way to experiment is to create a new Swift SpriteKit game from the new project template in Xcode, do your research on HealthKit, and see if you can just log the number of calories burned since some time point while your app is running. If you can do that, the rest is details (as in, the entire app :-)).

Here are what I think might be some helpful links, good luck on your project!

https://itunes.apple.com/us/book/swift-programming-language/id881256329?mt=11

https://developer.apple.com/library/ios/documentation/HealthKit/Reference/HealthKit_Framework/index.html

You'll also find some good documentation on SpriteKit (references and guides) on the iOS Developer Library site.



来源:https://stackoverflow.com/questions/26425144/accessing-data-from-healthkit-with-swift

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!