I'm trying to have to steps update in my watchface whenever the screen wakes up. It appears to be working whenever I view my watch, my steps are displayed, and up to date. But if I open another app, and then go back to the watch screen, my steps are no longer displayed, but have disappeared entirely.
This is the code I was using to have the steps update:
function updateSteps() {
let steps = (userActivity.today.local.steps.toLocaleString() || 0) + " STEPS";
mySteps.text = `${steps}`;
}
display.onchange = () => updateSteps();
Answered! Go to the Best Answer.
Fitbit Developers oversee the SDK and API forums. We're here to answer questions about Fitbit developer tools, assist with projects, and make sure your voice is heard by the development team.
try:
display.onchange = function() {
if (display.on) {
console.log("ON");
updateSteps();
}
}
Fitbit Developers oversee the SDK and API forums. We're here to answer questions about Fitbit developer tools, assist with projects, and make sure your voice is heard by the development team.
Thanks @JonFitbit. But I had previously tried this method, and the steps never seem to update on their own.
If I use both lines that you suggested, then the steps only actually update when I go back to the watchface from another app. For example, my steps will remain the same, no matter how many times the screen wakes up, UNTIL I open the 'Today' app, and then go back to the main watchface. Only then will the steps actually update on that screen.
Best Answer
Fitbit Developers oversee the SDK and API forums. We're here to answer questions about Fitbit developer tools, assist with projects, and make sure your voice is heard by the development team.
You need both, as per my example.
One fires when the display comes on, the other fires when the app is launched.
Best Answer
Fitbit Developers oversee the SDK and API forums. We're here to answer questions about Fitbit developer tools, assist with projects, and make sure your voice is heard by the development team.
Are you importing display?
import { display } from "display";
Also, check you don't have another variable named display.
Best Answer
Fitbit Developers oversee the SDK and API forums. We're here to answer questions about Fitbit developer tools, assist with projects, and make sure your voice is heard by the development team.
put a console.log inside the updateSteps(), does that output when the display wakes?
Best AnswerNope, it only logs when I close and then re-open the app. Not from the screen wake.
//Update steps display.onchange = () => updateSteps(); updateSteps();
Best Answer
Fitbit Developers oversee the SDK and API forums. We're here to answer questions about Fitbit developer tools, assist with projects, and make sure your voice is heard by the development team.
try:
display.onchange = function() {
if (display.on) {
console.log("ON");
updateSteps();
}
}
That seemed to do it. 🙂
Confirmed that the actual steps updated on the watchface as well.
Best Answer