美文网首页
iOS 如何刷QQ运动步数

iOS 如何刷QQ运动步数

作者: CoderZNB | 来源:发表于2017-04-10 15:31 被阅读0次

昨天上QQ玩QQ步数的时候发现很多小伙伴的步数高的吓人,而我仅仅可怜的三位数,于是我就想我怎么能把这个步数刷刷,这样我就能占领整个QQ封面了--是时候装一波逼了😄,这不仅仅可以装逼,还可以做公益,大家应该都有玩过捐步吧,那可都是money啊,为了公益事业,我想这个应用必须得写了!!!!!

Demo

捐步截图

  • 捐步截图.PNG

用过苹果机都知道,苹果有个健康应用,其实第三方的应用都是从这里拿的步行数据,当然,不仅仅是步数数据,还有很多,以下都算

  • IMG_0010.PNG

怎么才能修改步数呢

答:HealthKit

什么是HealthKit

简单的说,HealthKit就是iOS8 以后出现的,苹果用来生成,存储,查询各种健康数据的一个API,包括iPhone本身创建的健身数据,或者第三方app创建的健康数据,都可以通过这个API进行读取和查询.也可以把HealthKit看成iPhone的健康数据的一个统一的数据库,同一个手机上的不用app的健康数据的读取都是直接面向healthKit,由HealthKit统一管理,来实现iOS上不同应用之间的健康数据的交互.微信(包括qq或者其他第三方app)上的运动步数,本质上也是通过HealthKit来读取的,所以,我们只需要新建一个app(当然,我这里只做开发环境),请求对HealthKit数据的写入权限,添加运动步数后,(qq或者其他第三方app)通过HealthKit读取我们手机上的健康数据中的运动步数后,自然读取后的运动步数就可以由我们随心所欲来修改了.当然,healthKit里面包含各种各种的健康数据,包括步数,睡眠,运动距离,卡路里,血压等等.想要查看这些数据非常简单,打开iPhone里面苹果自带的健康应用,非常直观的展示了我们的健康数据.

怎么用HealthKit

这部分内容不打算写了,其实没多少内容,这里附上我参考的链接:点击进入

核心代码

// 1创建 healthKitStore 对象
    self.healthKitStore = [[HKHealthStore alloc] init];
    
    // 2 创建 基于HKSampleType的健康对像
    // 2.1创建 height 类型
    HKSampleType *height = [HKSampleType quantityTypeForIdentifier:HKQuantityTypeIdentifierHeight];
    NSSet *healthDataToRead = [NSSet setWithArray:@[height]];
    HKSampleType *runing = [HKSampleType quantityTypeForIdentifier:HKQuantityTypeIdentifierStepCount];
    NSSet *healthDataToWrite = [NSSet setWithArray:@[runing]];
    
    // 3请求授权
    // 3.1第一个参数可写
    // 3.2第二个参数可读
    // 3.3第三个参数授权回调
    [_healthKitStore requestAuthorizationToShareTypes:healthDataToWrite readTypes:healthDataToRead completion:^(BOOL success, NSError * _Nullable error) {
        if (success) {
            NSLog(@"授权成功");
            [self reloadData];
        }
    }];

- (void)reloadData {
    
    HKQuantityType *stepType = [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierStepCount];
    
    [self fetchSumOfSamplesTodayForType:stepType unit:[HKUnit countUnit] completion:^(double stepCount, NSError *error) {
        NSLog(@"%f",stepCount);
        dispatch_async(dispatch_get_main_queue(), ^{
            _stepCount.text = [NSString stringWithFormat:@"%.f",stepCount];
        });
    }];
}

- (void)fetchSumOfSamplesTodayForType:(HKQuantityType *)quantityType unit:(HKUnit *)unit completion:(void (^)(double, NSError *))completionHandler {
    NSPredicate *predicate = [self predicateForSamplesToday];
    
    HKStatisticsQuery *query = [[HKStatisticsQuery alloc] initWithQuantityType:quantityType quantitySamplePredicate:predicate options:HKStatisticsOptionCumulativeSum completionHandler:^(HKStatisticsQuery *query, HKStatistics *result, NSError *error) {
        HKQuantity *sum = [result sumQuantity];
        
        if (completionHandler) {
            double value = [sum doubleValueForUnit:unit];
            
            completionHandler(value, error);
        }
    }];
    
    [self.healthKitStore executeQuery:query];
}

- (NSPredicate *)predicateForSamplesToday {
    NSCalendar *calendar = [NSCalendar currentCalendar];
    
    NSDate *now = [NSDate date];
    
    NSDate *startDate = [calendar startOfDayForDate:now];
    NSDate *endDate = [calendar dateByAddingUnit:NSCalendarUnitDay value:1 toDate:startDate options:0];
    
    return [HKQuery predicateForSamplesWithStartDate:startDate endDate:endDate options:HKQueryOptionStrictStartDate];
}
- (IBAction)writeStepcount:(UIButton *)sender {
     [self addstepWithStepNum:_textF.text.doubleValue];
}


- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {

    [self.view endEditing:YES];
}

- (void)addstepWithStepNum:(double)stepNum {
    
    HKQuantitySample *stepCorrelationItem = [self stepCorrelationWithStepNum:stepNum];
    
    [self.healthKitStore saveObject:stepCorrelationItem withCompletion:^(BOOL success, NSError *error) {
        dispatch_async(dispatch_get_main_queue(), ^{
            if (success) {
                [self.view endEditing:YES];
                UIAlertView *doneAlertView = [[UIAlertView alloc] initWithTitle:@"提示" message:@"添加成功" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
                [doneAlertView show];
                
                [self reloadData];
                
            }
            else {
                NSLog(@"The error was: %@.", error);
                UIAlertView *doneAlertView = [[UIAlertView alloc] initWithTitle:@"提示" message:@"添加失败" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
                [doneAlertView show];
                return ;
            }
        });
    }];
}
- (HKQuantitySample *)stepCorrelationWithStepNum:(double)stepNum {
    NSDate *endDate = [NSDate date];
    NSDate *startDate = [NSDate dateWithTimeInterval:-300 sinceDate:endDate];
    
    HKQuantity *stepQuantityConsumed = [HKQuantity quantityWithUnit:[HKUnit countUnit] doubleValue:stepNum];
    
    HKQuantityType *stepConsumedType = [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierStepCount];
    
    HKDevice *device = [[HKDevice alloc] initWithName:@"iPhone" manufacturer:@"Apple" model:@"iPhone 7 (Model 1660, 1778, 1779, 1780)" hardwareVersion:@"iPhone7" firmwareVersion:@"9.2" softwareVersion:@"10.2 (14C92)" localIdentifier:@"ZNBmm" UDIDeviceIdentifier:@"e5f56af41988fe84497f179dbccdfc081c7bd101"];

    HKQuantitySample *stepConsumedSample = [HKQuantitySample quantitySampleWithType:stepConsumedType quantity:stepQuantityConsumed startDate:startDate endDate:endDate device:device metadata:nil];
    return stepConsumedSample;
}

写在最后

为什么写这篇文章--------->
装逼算不算呢!1111111当然算,除此之外,也算是给小伙伴们一个思路吧,也为以后入Healthkit坑做好准备,加油,技术就是金钱啊,要是钱都是捐给我的话多好啊

相关文章

  • iOS 如何刷QQ运动步数

    昨天上QQ玩QQ步数的时候发现很多小伙伴的步数高的吓人,而我仅仅可怜的三位数,于是我就想我怎么能把这个步数刷刷,这...

  • QQ运动步数修改

    【此软件已和谐或已有新版本 请加群更新!】 《832955627》 〖关〗

  • 怎么刷运动步数

    今日教大家怎么刷运动步数,可以同步到VX和支*宝的,运动排行榜里好友是可以看到的,也就说不是自慰的! 不需要下载任...

  • iOS 教你修改运动步数(基于Healthkit)

    近日,看到糯米粉写的文章iOS 教你如何修改微信运动步数 ,趁着五一放假,也想来玩一下改微信运动步数,占领一下朋友...

  • 满满的13条干货分享给大家!希望喜欢。

    [if !supportLists]1.[endif]QQ运动红包。在QQ运动中即可找到,只要每天走到固定步数即可...

  • 180308收藏IOS-越狱逆向

    iOS 教你如何修改微信运动步数 - 简书http://www.jianshu.com/p/b8b7fd5447c...

  • iOS 逆向开发--配置Theos

    今早7点多,在微信公众号上看到一遍文章,《iOS 教你如何修改微信运动步数》,然后刚好昨天看《iOS应用逆向工程》...

  • iOS CMPedometer获取运动步数

    CMPedometer是iOS 8.0推出的,用来统计用户的的运动数据(步数、楼层、公里数等)。最近项目需...

  • 如何用小米运动改微信步数

    微信运动步数始终没有别人高怎么办?这里哆哆给大家分享一个微信运动步数修改器。可以直接修改微信、支付宝以及QQ的运动...

  • HealthKit 健康

    iOS HealthKit读取运动步数https://www.jianshu.com/p/ef9665c5734e...

网友评论

      本文标题:iOS 如何刷QQ运动步数

      本文链接:https://www.haomeiwen.com/subject/gavsattx.html