How to access historical M7 data?

Discussion in 'iOS Programming' started by declan0872, Apr 7, 2015.

  1. declan0872 macrumors newbie

    Joined:
    Apr 4, 2015
    #1
    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!
     
  2. moonman239 macrumors 68000

    Joined:
    Mar 27, 2009
    #2
    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.
     
  3. DennisBlah macrumors 6502

    DennisBlah

    Joined:
    Dec 5, 2013
    Location:
    The Netherlands
    #3
    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);
                }
        ];
    
     

Share This Page