I've been working on a cross-platform app built with Expo and I've been having trouble with the Pedometer in iOS. It works fine on android, but on iOS while it does ask for permissions it fails to retrieve values with a promise rejection.
I've tried going back over the docs to see if there's been changes I need to implement. The docs do indeed seem to have changed to import from expo-sensors instead of expo. I tried this, it does not change the promise rejection on iOS. Additionally, using this import give an error for android that using dates has not been implemented yet. I checked the expo-sensors docs and the standalone expo-sensors has been deprecated and is part of the main branch, though the expo docs say to use this import now. In addition, you get the same errors on the code examples in the docs on their emulator but there's no notes about iOS being broken that I can find.
https://docs.expo.io/versions/latest/sdk/pedometer/
The import syntax I'm using:
import {Pedometer} from 'expo';
And how I'm using the Pedometer:
Pedometer.isAvailableAsync().then(
result => {
this.setState({
pedometerAvailability: String(result)
});
},
error => {
this.setState({
pedometerAvailability: "No pedometer available: " + error
});
}
);
//start and end times for the day
//Take date by the the diary date
let endDay = new Date(Moment(diaryDate).toDate().valueOf());
let startDay = new Date(Moment(diaryDate).toDate().valueOf());
let today = new Date();
//are we checking today? If not end day should be set as the end of the day
if (today.getDay() !== endDay.getDay()){
this.setTime(endDay, 23, 59, 59);
}
//setting time for startDay
this.setTime(startDay, 0, 0, 0);
//making call
Pedometer.getStepCountAsync(startDay, endDay).then(
result => {
this.setState({
stepCount:result.steps
});
},
error => {
this.setState({
stepCount:"Could not get stepCount:" + error
});
}
);
};
setTime = (date, h, m, s) =>{
date.setHours(h);
date.setMinutes(m);
date.setSeconds(s);
};
iOS should behave like Android according to the docs, but maybe I'm going wrong somewhere?