Objective-C修改运动步数
2016-09-28 10:23
197 查看
iOS上面的计步应用都是访问“健康”内的数据,所以只要修改“健康”的数据就可以达到修改QQ或者微信步数的需求,装X神技。
首先打开HealthKit:TARGETS–Capabilities–HealthKit
然后倒入导入HealthKit.framework:TARGETS–Build Phases–Link Binary With Libraries
导入头文件:
主要的代码:
stepsCounts为要修改的步数,需要注意的是:要回到主线程来进行UI操作,显示Alert,而且需要真机运行。
GitHub上demo地址:https://github.com/FEverStar/ChangeStepCounts.git
首先打开HealthKit:TARGETS–Capabilities–HealthKit
然后倒入导入HealthKit.framework:TARGETS–Build Phases–Link Binary With Libraries
导入头文件:
#import <HealthKit/HealthKit.h>
主要的代码:
//获取权限 HKQuantityType *stepCountType = [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierStepCount]; NSSet *writeDataTypes = [NSSet setWithObjects:stepCountType, nil]; [self.healthStore requestAuthorizationToShareTypes:writeDataTypes readTypes:nil completion:^(BOOL success, NSError * _Nullable error) { }]; //修改步数 HKQuantityType * quantityTypeIdentifier = [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierStepCount]; HKQuantity *quantity = [HKQuantity quantityWithUnit:[HKUnit countUnit] doubleValue:stepsCounts]; HKQuantitySample *temperatureSample = [HKQuantitySample quantitySampleWithType:quantityTypeIdentifier quantity:quantity startDate:[NSDate date] endDate:[NSDate date] metadata:nil]; [self.healthStore saveObject:temperatureSample withCompletion:^(BOOL success, NSError * _Nullable error) { if (success) { dispatch_async(dispatch_get_main_queue(), ^{ [self _showAlert:@"添加成功"]; }); }else{ dispatch_async(dispatch_get_main_queue(), ^{ [self _showAlert:@"添加失败"]; }); } }];
stepsCounts为要修改的步数,需要注意的是:要回到主线程来进行UI操作,显示Alert,而且需要真机运行。
GitHub上demo地址:https://github.com/FEverStar/ChangeStepCounts.git
相关文章推荐
- iOS 教你如何修改微信运动步数
- 手把手教你修改iOS版QQ的运动步数
- 基于Xposed修改微信运动步数
- 基于Xposed修改微信运动步数
- 基于Xposed修改微信运动步数
- 2017QQ,微信安卓修改运动步数APP无限刷步数方法教程
- 基于Xposed修改微信运动步数
- Android实现简易计步器功能,隔天步数清零,查看历史运动纪录
- 微信小程序实现运动步数排行功能(可删除)
- Objective-C 【OC语法:不能修改 某个对象的 结构体属性的 成员】
- Unity编辑器下获取动画的根运动状态并修改
- 【Android自定义View实战】之仿QQ运动步数圆弧及动画,Dylan计步中的控件StepArcView
- Objective-C修改cell左滑按钮背景色
- 动态映射objective-c的对象方法修改空指针
- Objective-C实现修改和删除nsstring 的方法
- 基于Xposed修改微信运动步数
- Android自定义View实现仿QQ实现运动步数效果
- Objective-C 利用OC的消息机制,使用Method Swizzling进行方法修改
- objective-c的NSMutableDictionary对象数据修改测试
- objective 修改plist文件