@webileapps/nativescript-healthkit
一款用于获取 HealthKit 数据的 iOS NativeScript 插件。
npm i --save @webileapps/nativescript-healthkit
- 版本:0.0.4
- GitHub:
- NPM: https://npmjs.net.cn/package/%40webileapps%2Fnativescript-healthkit
- 下载量
- 前一天: 0
- 上周: 0
- 上个月: 0
nativescript-healthkit
用于从 iOS Healthkit 获取数据的 NativeScript 插件。
安装
tns plugin add @webileapps/nativescript-healthkit
权限
将以下文件添加到您的 app/App_Resources/iOS/app.entitlements
文件夹
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.developer.healthkit</key>
<true/>
<key>com.apple.developer.healthkit.access</key>
<array>
<string>health-records</string>
</array>
</dict>
</plist>
使用字符串。
以下 plist 键由插件注入。在 app/App_Resources/iOS/Info.plist
中创建或添加以覆盖这些键。
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSHealthClinicalHealthRecordsShareUsageDescription</key>
<string>We need your clinical health data to aggregate your health stats over time.</string>
<key>NSHealthShareUsageDescription</key>
<string>We need your health data to aggregate your health stats over time.</string>
</dict>
</plist>
使用方法
检查设备上是否启用了 HealthKit。
import { isHealthDataAvailable } from "@webileapps/nativescript-healthkit"
console.log("Is health data available", isHealthDataAvailable());
获取自上一个日期以来的健康数据。例如,过去 60 天的数据。
import { getHealthDataSince } from "@webileapps/nativescript-healthkit";
const date = new Date();
date.setDate(date.getDate() - 60);
try {
const data = await getHealthDataSince(date);
console.log(data.active_minutes, data.calories_expended, data.distance, data.heart_rate, data.step_count);
} catch (error) {
console.error(error);
}
许可证
Apache 许可证版本 2.0,2004 年 1 月