资源简介
获取iOS系统健康数据:卡路里,步数等。步数可以获取一个时间段,或者实时获取当天步数,自己设置。参考:http://blog.csdn.net/doing111/article/details/45167317#comments
代码片段和文件信息
//
// HealthManager.m
// zoubao
//
// Created by 李聪 on 15/4/20.
// Copyright (c) 2015年 李聪. All rights reserved.
//
#import “HealthManager.h“
#import
#import “HKHealthStore+AAPLExtensions.h“
#define HKVersion [[[UIDevice currentDevice] systemVersion] doubleValue]
@implementation HealthManager
+(id)shareInstance
{
static id manager ;
static dispatch_once_t onceToken;
dispatch_once(&onceToken ^{
manager = [[[self class] alloc] init];
});
return manager;
}
/*!
* @author Lcong 15-04-20 17:04:44
*
* @brief 检查是否支持获取健康数据
*/
- (void)getPermissions:(void(^)(BOOL success))Handle
{
if(HKVersion >= 8.0)
{
if ([HKHealthStore isHealthDataAvailable]) {
if(self.healthStore == nil)
self.healthStore = [[HKHealthStore alloc] init];
/*
组装需要读写的数据类型
*/
NSSet *writeDataTypes = [self dataTypesToWrite];
NSSet *readDataTypes = [self dataTypesRead];
/*
注册需要读写的数据类型,也可以在“健康”APP中重新修改
*/
[self.healthStore requestAuthorizationToShareTypes:writeDataTypes readTypes:readDataTypes completion:^(BOOL success NSError *error) {
if (!success) {
DebugLog(@“%@\n\n%@“error [error userInfo]);
return ;
}
else
{
Handle(YES);
}
}];
}
}
}
/*!
* @author Lcong 15-04-20 16:04:42
*
* @brief 写权限
*
* @return 集合
*/
- (NSSet *)dataTypesToWrite
{
// HKQuantityType *heightType = [HKobjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierHeight];
// HKQuantityType *weightType = [HKobjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierBodyMass];
// HKQuantityType *temperatureType = [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierBodyTemperature];
// HKQuantityType *activeEnergyType = [HKobjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierActiveEnergyBurned];
//
// return [NSSet setWithobjects:heightType temperatureType weightTypeactiveEnergyTypenil];
return [NSSet setWithobjects:nil];
}
/*!
* @author Lcong 15-04-20 16:04:03
*
* @brief 读权限
*
* @return 集合
*/
- (NSSet *)dataTypesRead
{
HKQuantityType *activeEnergyType = [HKobjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierActiveEnergyBurned];
HKQuantityType *heightType = [HKobjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierHeight];
HKQuantityType *weightType = [HKobjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierBodyMass];
HKQuantityType *temperatureType = [HKobjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierBodyTemperature];
HKCharacteristicType *birthdayType = [HKobjectType characteristicTypeForIdentifier:HKCharacteristicTypeIdentifierDateOfBirth];
HKCha
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2015-08-18 16:25 Health\
文件 1276 2015-04-21 17:29 Health\HealthManager.h
目录 0 2015-11-24 15:31 __MACOSX\
目录 0 2015-11-24 15:31 __MACOSX\Health\
文件 263 2015-04-21 17:29 __MACOSX\Health\._HealthManager.h
文件 9635 2015-07-23 10:41 Health\HealthManager.m
文件 263 2015-07-23 10:41 __MACOSX\Health\._HealthManager.m
文件 575 2015-04-20 12:30 Health\HKHealthStore+AAPLExtensions.h
文件 263 2015-04-20 12:30 __MACOSX\Health\._HKHealthStore+AAPLExtensions.h
文件 1520 2015-07-10 11:40 Health\HKHealthStore+AAPLExtensions.m
文件 263 2015-07-10 11:40 __MACOSX\Health\._HKHealthStore+AAPLExtensions.m
文件 212 2015-08-18 16:25 __MACOSX\._Health
- 上一篇:正星加油机转接板接线说明
- 下一篇:openGL 模拟太阳系行星自转公转
评论
共有 条评论