11-12-2017 19:01
11-12-2017 19:01
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.
11-15-2017 14:43
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.
11-15-2017 14:43
try:
display.onchange = function() {
if (display.on) {
console.log("ON");
updateSteps();
}
}
11-14-2017 12:55
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.
11-14-2017 12:55
The display onchange event doesn't fire if the display is already on.
Just call updateSteps() when your app launches.
display.onchange = () => updateSteps(); updateSteps();
Best Answer11-15-2017 12:52
11-15-2017 12:52
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 Answer11-15-2017 13:44
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.
11-15-2017 13:44
You need both, as per my example.
One fires when the display comes on, the other fires when the app is launched.
Best Answer11-15-2017 13:50
11-15-2017 13:50
I currently have both, but the display coming on one doesn't seem to be firing.
Best Answer11-15-2017 13:58
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.
11-15-2017 13:58
Are you importing display?
import { display } from "display";
Also, check you don't have another variable named display.
Best Answer11-15-2017 14:04
11-15-2017 14:04
It is importing, and no other display variables.
Best Answer11-15-2017 14:30
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.
11-15-2017 14:30
put a console.log inside the updateSteps(), does that output when the display wakes?
Best Answer11-15-2017 14:40
11-15-2017 14:40
Nope, it only logs when I close and then re-open the app. Not from the screen wake.
//Update steps display.onchange = () => updateSteps(); updateSteps();
Best Answer11-15-2017 14:43
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.
11-15-2017 14:43
try:
display.onchange = function() {
if (display.on) {
console.log("ON");
updateSteps();
}
}
11-15-2017 14:49
11-15-2017 14:49
That seemed to do it. 🙂
Confirmed that the actual steps updated on the watchface as well.
Best Answer