02-09-2020 15:32
02-09-2020 15:32
Hi guys,
I am trying to access the goal number for steps and I am getting the error 'Cannot read property 'steps' of undefined' when running the code on the simulator. I have activated permissions for Activity. Any idea what I am doing wrong?
Below is my code:
index.js
import clock from "clock";
import document from "document";
import { preferences } from "user-settings";
import * as util from "../common/utils";
import { me as appbit } from "appbit";
import { goals } from "user-activity";
// Update the clock every minute
clock.granularity = "seconds";
// Get a handle on the <text> element
const myLabel = document.getElementById("myLabel");
// Update the <text> element every tick with the current time
clock.ontick = (evt) => {
let today = evt.date;
let hours = today.getHours();
if (preferences.clockDisplay === "12h") {
// 12h format
hours = hours % 12 || 12;
} else {
// 24h format
hours = util.zeroPad(hours);
}
let mins = util.zeroPad(today.getMinutes());
myLabel.text = `${hours}:${mins}`;
}
// Get goals
if (appbit.permissions.granted("access_activity")) {
console.log(`${goals.adjusted.steps} Step Goal`);
if (goals.local.elevationGain !== undefined) {
console.log(`${goals.adjusted.elevationGain} Floor Goal`);
}
}
Answered! Go to the Best Answer.
02-09-2020 15:50
02-09-2020 15:50
'adjusted' is not a member of 'goals'. See here.
02-09-2020 15:50
02-09-2020 16:14
02-09-2020 16:14
Good catch Catplace!
The example code in the documentation must have an error.
You are correct, calling goals.steps solves the problem.
if (appbit.permissions.granted("access_activity")) {
console.log(`${goals.steps} Step Goal`);
if (goals.elevationGain !== undefined) {
console.log(`${goals.elevationGain} Floor Goal`);
}
}