当前位置: 首页 > news >正文

烟台做网站公司郑州竞价托管代运营

烟台做网站公司,郑州竞价托管代运营,专门做网站的公司 南阳,技术支持 海安网站建设文章目录 一、简介二、权限配置1. 在开发者账号中勾选HealthKit2. 在targets的capabilities中添加HealthKit。3. infoPlist需要配置权限 三、创建健康数据管理类1. 引入头文件2. 健康数据读写权限3. 检查权限4. 读取步数数据5. 写入健康数据 四、运行获取权限页面 一、简介 He…

文章目录

  • 一、简介
  • 二、权限配置
    • 1. 在开发者账号中勾选HealthKit
    • 2. 在targets的capabilities中添加HealthKit。
    • 3. infoPlist需要配置权限
  • 三、创建健康数据管理类
    • 1. 引入头文件
    • 2. 健康数据读写权限
    • 3. 检查权限
    • 4. 读取步数数据
    • 5. 写入健康数据
  • 四、运行获取权限页面

一、简介

HealthKit是一款用于搜集和办理医疗和健康相关数据的开发工具包,它为开发者供给了拜访用户健康数据的API和框架,并使得这些数据能够与iOS设备上的其他应用程序相互共享。

HealthKit允许应用程序搜集和办理各种类型的健康数据,包含身体丈量数据(如体重、身高和心率)、健身数据(如步数和距离)、饮食数据、睡觉数据和心理健康数据等。这些数据能够从多个来历搜集,如从硬件设备(如智能手表、智能手机和健身跟踪器)中获取,或由用户手动输入。

二、权限配置

1. 在开发者账号中勾选HealthKit

在这里插入图片描述

2. 在targets的capabilities中添加HealthKit。

在这里插入图片描述

3. infoPlist需要配置权限

Privacy - Health Share Usage Description
需要您的同意,才能访问健康更新,给您带来更好的服务
Privacy - Health Update Usage Description
需要您的同意,才能分享健康数据,给您带来更好的服务
在这里插入图片描述

注意:iOS13 这里描述太粗糙,会导致程序崩溃。

三、创建健康数据管理类

1. 引入头文件

import HealthKit

2. 健康数据读写权限

// 写权限private func dataTypesToWrite() -> Set<HKSampleType> {// 步数let stepCountType = HKObjectType.quantityType(forIdentifier: .stepCount)// 身高let heightType = HKObjectType.quantityType(forIdentifier: .height)// 体重let weightType = HKObjectType.quantityType(forIdentifier: .bodyMass)// 活动能量let activeEnergyType = HKObjectType.quantityType(forIdentifier: .activeEnergyBurned)// 体温let temperatureType = HKObjectType.quantityType(forIdentifier: .bodyTemperature)// 睡眠分析let sleepAnalysisType = HKObjectType.categoryType(forIdentifier: .sleepAnalysis)let setTypes = Set([stepCountType, heightType, weightType, activeEnergyType, temperatureType, sleepAnalysisType].compactMap { $0 })return setTypes}// 读权限private func dataTypesToRead() -> Set<HKObjectType> {// 步数let stepCountType = HKObjectType.quantityType(forIdentifier: .stepCount)// 身高let heightType = HKObjectType.quantityType(forIdentifier: .height)// 体重let weightType = HKObjectType.quantityType(forIdentifier: .bodyMass)// 体温let temperatureType = HKObjectType.quantityType(forIdentifier: .bodyTemperature)// 出生日期let birthdayType = HKObjectType.characteristicType(forIdentifier: .dateOfBirth)// 性别let sexType = HKObjectType.characteristicType(forIdentifier: .biologicalSex)// 步数+跑步距离let distance = HKObjectType.quantityType(forIdentifier: .distanceWalkingRunning)// 活动能量let activeEnergyType = HKObjectType.quantityType(forIdentifier: .activeEnergyBurned)// 睡眠分析let sleepAnalysisType = HKObjectType.categoryType(forIdentifier: .sleepAnalysis)let setTypes = Set([stepCountType, heightType, weightType, activeEnergyType, birthdayType, sexType, distance, temperatureType, sleepAnalysisType].compactMap { $0 })return setTypes}

3. 检查权限

/// 检查是否支持获取健康数据public func authorizeHealthKit(_ compltion: ((_ success: Bool, _ error: Error?) -> Void)?) {guard HKHealthStore.isHealthDataAvailable() == true else {let error = NSError(domain: "不支持健康数据", code: 2, userInfo: [NSLocalizedDescriptionKey: "HealthKit is not available in th is Device"])if let compltion = compltion {compltion(false, error)}return}let writeDataTypes = dataTypesToWrite()let readDataTypes = dataTypesToRead()healthStore.requestAuthorization(toShare: writeDataTypes, read: readDataTypes) { success, error inif let compltion = compltion {compltion(success, error)}}}

4. 读取步数数据

/// 获取步数public func getStepCount(_ completion: @escaping ((_ stepValue: String?, _ error: Error?) -> Void)) {// 要检索的数据类型。guard let stepType = HKObjectType.quantityType(forIdentifier: .stepCount) else {let error = NSError(domain: "不支持健康数据", code: 2, userInfo: [NSLocalizedDescriptionKey: "HealthKit is not available in th is Device"])completion(nil, error)return}// NSSortDescriptors用来告诉healthStore怎么样将结果排序。let start = NSSortDescriptor.init(key: HKSampleSortIdentifierStartDate, ascending: false)let end = NSSortDescriptor.init(key: HKSampleSortIdentifierEndDate, ascending: false)/*@param         sampleType      要检索的数据类型。@param         predicate       数据应该匹配的基准。@param         limit           返回的最大数据条数@param         sortDescriptors 数据的排序描述@param         resultsHandler  结束后返回结果*/let query = HKSampleQuery.init(sampleType: stepType, predicate: HealthKitManager.getStepPredicateForSample(), limit: HKObjectQueryNoLimit, sortDescriptors: [start, end]) { _, results, error inguard let results = results else {completion(nil, error)return}print("resultCount = \(results.count) result = \(results)")// 把结果装换成字符串类型var totleSteps = 0results.forEach({ quantitySample inguard let quantitySample = quantitySample as? HKQuantitySample else {return}let quantity = quantitySample.quantitylet heightUnit = HKUnit.count()let usersHeight = quantity.doubleValue(for: heightUnit)totleSteps += Int(usersHeight)})print("最新步数:\(totleSteps)")completion("\(totleSteps)", error)}healthStore.execute(query)}

5. 写入健康数据

/// 写入数据public func writeStep() {let steps = HKObjectType.quantityType(forIdentifier: .stepCount)!let quantity = HKQuantity(unit: HKUnit.count(), doubleValue: 1000)let now = Date()let start = now.addingTimeInterval(-3600 * 24)let end = nowlet sample = HKQuantitySample(type: steps, quantity: quantity, start: start, end: end)let healthStore = HKHealthStore()healthStore.save(sample) { (success, _) inif success {// 数据已写入 HealthKit} else {// 写入数据失败}}}

四、运行获取权限页面

在这里插入图片描述

http://www.wangmingla.cn/news/56531.html

相关文章:

  • 深圳出国劳务公司官网湛江seo
  • 网站模板 整站源码电商网站平台
  • vs做的网站源代码如何刷seo关键词排名
  • 泰安网站建设怎么样网络营销的重要性
  • 东营做网站的公司台州网站seo
  • 宁波网站制作与推广网络营销推广方案设计
  • 长沙给中小企业做网站的公司桔子seo查询
  • 织梦网站案例百度账号登录
  • 日本亲子游哪个网站做的好宁德市住房和城乡建设局
  • 滨江区网站开发公司看今天的新闻
  • 如何做网站跳转百度云搜索引擎 百度网盘
  • 购物网站建设信息seo关键词选择及优化
  • 律师网站建设 优帮云网络营销价格策略有哪些
  • 如何阿里巴巴网站做推广批量关键词调排名软件
  • 电子商务网站有哪些功能重庆的seo服务公司
  • 免费模板做网站视频号视频下载助手app
  • 哪里可以找到做网站的营销策划案ppt优秀案例
  • 唐山网站建设正规公司seo店铺描述例子
  • 乐清网站改版公司免费的黄冈网站有哪些平台
  • 江西住房和城乡建设部网站如何创建个人网站免费
  • 品牌网站建设公外贸公司如何做推广
  • 网站开发判断是否为手机在线培训
  • 桐庐网站建设全国疫情高峰感染高峰
  • 免费设计海报seo专员简历
  • ps网站轮播图怎么做的seo的中文是什么
  • 自己在电脑上建文档做网站怎么做键词优化排名
  • 网络推广专员任职要求宁波关键词优化品牌
  • 企业门户网站建设论文用html制作淘宝网页
  • wordpress图片网站模板网站免费
  • 网站建设项目设计报告seo短视频保密路线