目录
1、配置工程
注意:Team这个地方必须是企业的或者是公司的,不能是Personal Team。如下图

2、设置Capabilities
设置完了之后,左侧会出现 XZHealthDemo.entitlements。如下图:


3、设置 Info.plist
注意:描述语句只能写 "some string value stating the reason",其他的都会崩溃。

Privacy - Health Share Usage Description // 读取权限
some string value stating the reason
Privacy - Health Update Usage Description // 写入权限
some string value stating the reason
或者
<key>NSHealthShareUsageDescription</key>
<string>some string value stating the reason</string>
<key>NSHealthUpdateUsageDescription</key>
<string>some string value stating the reason</string>
4、错误解决
出现错误:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'NSHealthUpdateUsageDescription must be set in the app's Info.plist in order to request write authorization for th

本文详细介绍了如何在Swift项目中配置HealthKit,设置Capabilities和Info.plist,解决授权问题,以及编写代码来获取和修改手机计步数据。包括判断设备支持、请求权限、保存和查询步数等关键步骤,并提供了demo下载链接。
最低0.47元/天 解锁文章
2327

被折叠的 条评论
为什么被折叠?



