ios - CMPedometer queryPedometerDataFromDate returns error 103 -
i'm trying query pedometer cache on iphone 6 ios 8.1.2, i'm using objective-c, have imported coremotion framework , included in project code looks this
nsdate *startdate = [[nsdate date] datebyaddingtimeinterval:-60*60*12]; nsdate *enddate = [nsdate date]; cmpedometer *pedo = [[cmpedometer alloc]init]; [pedo querypedometerdatafromdate:startdate todate:enddate withhandler:^(cmpedometerdata *pedometerdata, nserror *error) { if (error) { nslog(@"error: %@", error); } }];
this gives me error: error domain=cmerrordomain code=103 "the operation couldn’t completed. (cmerrordomain error 103.)"
if exact same thing in swift this
var datestring = "2014-12-15" var dateformatter = nsdateformatter() dateformatter.dateformat = "yyyy-mm-dd" var startdate = dateformatter.datefromstring(datestring) var enddate = nsdate() pedometer.querypedometerdatafromdate(startdate, todate: enddate){ (data, error) -> void in if error != nil { println("there error requesting data pedometer: \(error)") } else { println(data) } }
i pedometer data , no errors.
in both cases accept popup telling me accept tracking physical activity. have double checked app has read access physical activity data under anonymity settings.
can explain i'm doing wrong ?
you should hold cmpedometer variables property of class, not local variables. , work.
Comments
Post a Comment