Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

declan0872

macrumors newbie
Original poster
Apr 4, 2015
2
0
Hi all,

I need to access the historical data that the motion coprocessor (M7) has collected for my app and display it.

But I'm not sure of how to query the chip in oder to do so. I know that I have to use the CMStepCounter library but don't know how to access it exactly.

Anyone know how I would do this or what should I be looking up?


Thanks a million!
 

moonman239

Cancelled
Mar 27, 2009
1,541
32
I'm not all too familiar with accessing M7 data, but you can make your app store data as the app receives it using Core Data.
 

DennisBlah

macrumors 6502
Dec 5, 2013
485
2
The Netherlands
Do you mean something like this?
Example for all steps made of today:

Code:
    NSOperationQueue *stepQueue = [[NSOperationQueue alloc] init]; //Init setpQueue
    stepQueue.maxConcurrentOperationCount = 1;

    CMStepCounter *myStepCounter = [[CMStepCounter alloc] init]; //Init stepcounter

    NSDate *tillDateTime = [NSDate date]; //init date till ( NOW )
 
    NSCalendar *calendar = [NSCalendar autoupdatingCurrentCalendar];
    NSDateComponents *components = [calendar
            components:NSYearCalendarUnit
            | NSMonthCalendarUnit
            | NSDayCalendarUnit
            fromDate:tillDateTime];

   NSDate *fromDateTime = [calendar dateFromComponents:components]; //init date from

    //Get the steps between the 2 dates
    [myStepCounter stepCounter queryStepCountStartingFrom:fromDateTime
            to:tillDateTime
            toQueue:stepQueue
            withHandler:^(NSInteger stepAmount, NSError *error) {
                if (error)
                    //105 == not authorized
                    NSLog(@"%@", [error localizedDescription]);
                else
                    NSLog(@"Steps between datetimes : %i", stepAmount);
            }
    ];
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.