Forum Archive

Objc_tools Library

scj643

https://github.com/scj643/objc_tools
My pride and joy

I also have a slack chat for it reply if you are interested.

purple_cyborg

@scj643 Awesomeness

scj643

I also need people to help with documentation and refactoring

ryanryanryan

@scj643 I know it must be disturbing, but may I ask if you can help me to transfer CMPedometer query into objc_ulti codes? I read a lot of your wonderful obj scripts, and they are amazing!

I want to query the step data using objc_ulti, but I know nothing of ObjC :(

Here's the code I searched on the internet which may be helpful.
```
//initialize
self.pedometer = [[CMPedometer alloc]init];

//if step counting is available
if ([CMPedometer isStepCountingAvailable]) {
    [_pedometer queryPedometerDataFromDate:[NSDate dateWithTimeIntervalSinceNow:-60*60*24*2] toDate:[NSDate dateWithTimeIntervalSinceNow:-60*60*24*1] withHandler:^(CMPedometerData * _Nullable pedometerData, NSError * _Nullable error) {
        if (error) {
            NSLog(@"error====%@",error);
        }else {
            NSLog(@"Steps====%@",pedometerData.numberOfSteps);
            NSLog(@"Distance====%@",pedometerData.distance);
        }
    }];
}else{
    NSLog(@"Unavailable");
}```

No matter what, thanks for your contributions.

shaun-h

I did a quick translation of the code to run with objc_utils

from objc_util import ObjCClass, ObjCBlock, c_void_p, ns, ObjCInstance

def getData(_cmd, pedometerData, error):
    ped = ObjCInstance(pedometerData)

    if not error == None:
        err = ObjCInstance(error)
        print('error===='+str(err))
    else:
        print('Steps===='+str(ped.numberOfSteps()))
        print('Distance===='+str(ped.distance()))

ped_block = ObjCBlock(getData, restype=None, argtypes=[c_void_p, c_void_p, c_void_p])
CMPedometer = ObjCClass('CMPedometer')
NSDate = ObjCClass('NSDate')

ped = CMPedometer.alloc().init()

if CMPedometer.isStepCountingAvailable():
    fromDate = NSDate.dateWithTimeIntervalSinceNow_(-60*60*24*2)
    toDate = NSDate.dateWithTimeIntervalSinceNow_(-60*60*24*1)
    ped.queryPedometerDataFromDate_toDate_withHandler_(ns(fromDate),ns(toDate),ped_block)
else:
    print('Unavailable')

I hope it helps.