使用Swift从HealthKit访问数据 [英] Accessing data from HealthKit with Swift

查看:88
本文介绍了使用Swift从HealthKit访问数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Swift(和Xcode)的一个完全菜鸟,事实上,我(某种程度上)知道的唯一编程语言是Javascript.

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

我正在尝试制作Swift SpriteKit游戏,我想获取HealthKit中消耗的卡路里数量.

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

想法是,使用Endomondo等其他应用程序,我的游戏将为您燃烧的卡路里提供更多的积分.我的应用程序实际上没有跟踪任何内容,我只想访问Health App中其他应用程序留下的其他数据.

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.

这甚至有可能吗?(我正在运行从Mac OS X到Xcode的所有内容的最新版本)

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

推荐答案

当然.我认为从技术上讲,没有任何因素可以阻止您调用游戏中的HealthKit API.实际上,您可以随意混合使用iOS提供的任何公共框架.

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是一个非常丰富的API,它具有许多访问大量不同类型数据的方式,并且您现在实际上只对一小部分感兴趣,因此一种快速的实验方法是创建一个新的Swift SpriteKit游戏从Xcode的新项目模板中,对HealthKit进行研究,看看是否可以记录自应用程序运行某个时间点以来燃烧的卡路里数量.如果可以的话,剩下的就是细节了(就像整个应用程序一样:-)).

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/我们/book/swift-programming-language/id881256329?mt = 11

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

您还可以在iOS开发人员库网站上的SpriteKit(参考和指南)上找到一些不错的文档.

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

这篇关于使用Swift从HealthKit访问数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆