I'm working on building a fitness app that's main functionality will be around capturing step counts using the iOS Core Motion Pedometer. Using the old code listed below, I get a value that seems correct; however when I went out to follow Appcelerators documentation I noticed that there was a new way of doing this using the pedometer. Following Appcelerators documentation, I implemented the identical code given in the Pedometer example and the step count value that is now being returned is inaccurate. For 10 steps it reports a value of 200-300 and continues to grow from there. I also noticed that the .createPedometer method isn't in the documentation as a listed method. In fact, when trying to use the .createPedometer method yesterday, I was getting an error message back that said the method didn't exist; however, I upgraded the SDK to the latest and was then able to use it.
OLD code that seems to work correctly when outputting value to console:
var CoreMotion = require("ti.coremotion");
if (CoreMotion.isStepCountingAvailable()) {
// If it can, it starts the step counter and outputs the data to the console
CoreMotion.startStepCountingUpdates({stepCounts: 1}, function(e) {
//$.stepLabel.text = e.numberOfSteps;
// Ti.API.info(JSON.stringify(e.numberOfSteps));
//CoreMotion.startStepCountingUpdates({stepCounts: 1}, function(e){
Ti.API.info(JSON.stringify(e.numberOfSteps));
$.stepLabel.text = JSON.stringify(e.numberOfSteps);
});
}
New Pedometer code that gives inaccurate value:
var CoreMotion = require("ti.coremotion");
var pedometer = CoreMotion.createPedometer();
if(pedometer.isStepCountingAvailable()){
$.stepLabel.text = "IT IS NOW!";
pedometer.startPedometerUpdates({
start: new Date(new Date().getTime() - 60 * 60 * 1000)
}, function(e) {
$.stepLabel.text = e.numberOfSteps;
});
}
Appcelerator Documentation Link on how to use Pedometer example:
http://docs.appcelerator.com/platform/latest/#!/guide/Core_Motion_Module
Appcelerator Documentation Link on how to use the Core Motion Module that doesn't list updated methods:
http://docs.appcelerator.com/platform/latest/#!/api/Modules.CoreMotion
Hello, Please provide a full reproducible Alloy code which demonstrate the issue. Also provide the full steps to follow. We will try to regenerate the issue in our environment. Thanks.
Can you tell me how I can get you the attached project? It's 50mb and the size limit on attachments is 10MB? I cannot post this project to GIT.
I was able to attach the projects app directory with the code in it?
Hi may i know the coremotion module version you are using?
The fact that http://docs.appcelerator.com/platform/latest/#!/api/Modules.CoreMotion does not show the latest docs is a DOC issue that should be filed for [~bimmel]. Probably something isn't deployed correctly. Regarding the module itself, I guess you're using the latest 2.0.0 version which is pre-packaged in the latest Ti-release, coming from https://github.com/appcelerator-modules/ti.coremotion. I will debug the issue over the next days, thanks!
UPDATE: The method definitely returns the correct number of steps, bubbled from the native API. The difference between the two methods is, that the first one (
startStepCountingUpdates
) triggers the callback after a certain number of steps is reached. The new API provided by Apple (bridged tostartPedometerUpdates
) is based on a start date. That's why you receive 200 steps, because that's the number of steps in the last hour (60*60*1000). So if you want to use the step counter API, there is no problem in doing that, but Apple still courages to migrate it to the new API, that's why we also deprecated it. Considering that, I wouldn't and can't change anything, except of clarifying this behavior in the docs. Thanks!Hi, I also, get the similar behaviour as like reporter, new Pedometer code that gives inaccurate value but old code that seems to work correctly. *Steps To Reproduce:* 1. Create an Alloy app. 2. Replace the reporter attached code. 3. Import "ti.coremotion" module into the tiapp.xml file. 4. Run the app to the iPhone device. *Testing Environment:* Operating System Name = Mac OS X Version = 10.11.3 Architecture = 64bit # CPUs = 4 Memory = 8589934592 Node.js Node.js Version = 4.2.2 npm Version = 2.14.7 Titanium CLI CLI Version = 5.0.6 Titanium SDK SDK Version = 5.2.0.GA, 5.1.2.GA Target Platform = iphone Module Version: 2.0.0 iOS device version : 9.2.1 Thanks.
[~morahman] Did you read me comment above? It's no inaccurate value, it's just a different one. Further reading about the behavior [here (Example)](http://pinkstone.co.uk/how-to-access-the-step-counter-and-pedometer-data-in-ios-9/) and [here (Apple docs)](https://developer.apple.com/library/prerelease/ios/documentation/CoreMotion/Reference/CMPedometer_class/index.html#//apple_ref/occ/instm/CMPedometer/startPedometerUpdatesFromDate:withHandler:). If we use
new Date()
instead (which is the current date), it should give similar/same values. [~TaylorThompson] please validate so we can close this one, thank you for bringing up!This still isn't giving me the behavior I'd expect. I changed the start: line to three different things below: start: new Date() start: new Date(new Date()) start: new Date(new Date().getTime()) All of which give me similar behavior and I even have logic in my code so when I press a button it's supposed to give me back the last minute count of steps as what was provided in the documentation: $.btn.addEventListener('click', function(e){ pedometer.queryPedometerData({ start: new Date(new Date().getTime() - 60*1000), end: new Date() }, function (e) { $.stepHistory.text = "You walked " + e.numberOfSteps + " steps in the last minute."; });}); When I deploy to phone and shake 10 times I get an output of around 170-180 and another 10 steps results in 300-400. When clicking the button to give me the last minute worth of steps I get the same number. What I'd expect is if I walk 10 steps, I'd get a number close to 10? I'm just trying to figure out how to get there... SDK 5.2.0 GA Target Platform = iphoneModule Version: 2.0.0 iOS device version : 9.2.1
Hey Hans, Just wanted to check and see if you've been able to take another look at this yet? I tested the code above and still ended up with a value I didn't expect. I'm just trying to figure out what I need to do to get a value that I'd expect like what I get using the old code. In other words, if I walk 10 steps I'm needing to get a value close to 10. TT
Hey Taylor. Just thought the fact that it could be a thread-related issue. If you set
<run-on-main-thread>true</run-on-main-thread>
inside the<ios>
section of your tiapp.xml, does that change something? EDIT: Or try [this version](https://www.dropbox.com/s/dpxhwa5hjsczm2c/ti.coremotion-iphone-2.0.1.zip?dl=0). Thanks!I've tried both to run on main thread as well as use the new CoreMotion module you sent. Instead of returning (e.numberOfSteps) I've changed it to return e. Looking at the screenshot I've linked below, you can see where it shows a time difference of about 10 seconds in the start and end date. However, the numberOfSteps value is 226 which can't possible be correct. https://oneok.sharefile.com/d-s9c9d60f9953477b9
What's the status on this?
I'm working on a native example to compare it 1:1, but as we have other issues to also work on, it will take some more time here.
Hans, Any update on this yet? Do you know if there is any way to get health data out of the default iOS Health app as a workaround?
Hey Taylor! Unfortunately not, yet. Too many different things to work on. If you want to help me, grab one of the demo apps from the web accessing the Pedometer API and log your results here. I didn't forget the issue, but please give me some more time to sort things out.
[~TaylorThompson] You can still get the data from HealthKit (use Ti.HealthKit), but I still don't get how the data can be differently like natively, since no custom logic is applied. I will hand this one over to [~vijaysingh] have a second pair of eyes on it.
This issue is in Core motion module. So moving it to Module .
CMPedometerData properties "numberOfSteps" , "distance" etc., in Coremotion framework of apple , are NSNumber object type . In our code we were converting these properties to NSNumber assuming they are Int . PR: https://github.com/appcelerator-modules/ti.coremotion/pull/16
Hey [~TaylorThompson], can you test [ti.coremotion-iphone-2.0.1.zip](https://www.dropbox.com/s/dpxhwa5hjsczm2c/ti.coremotion-iphone-2.0.1.zip?dl=0) with yout setup? I know it has been a while, but the changes in the casting could actually do the difference. Thank you!
Test-Case:
New release: https://github.com/appcelerator-modules/ti.coremotion/releases/tag/v2.0.1
Cleaning up older fixed issues. If this issue should not have been closed as fixed, please reopen.