简体   繁体   English

使用Swift从HealthKit访问数据

[英]Accessing data from HealthKit with Swift

I'm a complete noob at Swift (and Xcode), as a matter of fact, the only programming language I (somewhat) know is Javascript. 我是Swift(和Xcode)的完全菜鸟,事实上,我(某种程度上)知道的唯一编程语言是Javascript。

I'm trying to make a Swift SpriteKit game, and I would like to access the number of calories burned in HealthKit. 我正在尝试制作Swift SpriteKit游戏,我想获取HealthKit中燃烧的卡路里数量。

The idea is that my game will provide more points the more calories you burn using other apps like Endomondo. 想法是,使用Endomondo等其他应用程序,我的游戏将为您燃烧的卡路里提供更多的积分。 My app does not actually track anything, I would just like to access other data left by other apps in the Health App. 我的应用程序实际上没有跟踪任何内容,我只想访问Health App中其他应用程序留下的其他数据。

Is this even possible? 这有可能吗? (I'm running the latest version of everything, from Mac OS X to Xcode) (我正在运行从Mac OS X到Xcode的所有内容的最新版本)

Certainly. 当然。 I don't think there is anything technically preventing you from making calls to the HealthKit APIs in your game. 我认为从技术上讲,没有任何因素可以阻止您在游戏中调用HealthKit API。 In fact, you're fairly free to mix and match the use of any public frameworks provided on iOS. 实际上,您可以随意混合使用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. HealthKit是一个非常丰富的API,可以通过多种方式访问​​大量不同类型的数据,并且您现在只对一小部分感兴趣,因此一种快速的实验方法是从新的版本创建一个新的Swift SpriteKit游戏。 Xcode中的项目模板,在HealthKit上进行研究,看看是否可以记录自应用程序运行某个时间点以来燃烧的卡路里数量。 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://itunes.apple.com/us/book/swift-programming-language/id881256329?mt=11

https://developer.apple.com/library/ios/documentation/HealthKit/Reference/HealthKit_Framework/index.html 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. 您还可以在iOS开发者库网站上的SpriteKit(参考和指南)上找到一些不错的文档。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM