Hello Ionic-Devs,
I'm trying to import some helper functions in my settings/index.jsx that I want to use also in the companion but I did not get it running:
companion/config.js:
import { settingsStorage } from "settings";
export function setDefaults()
{
...
}settings/index.jsx:
import * as config from "../companion/config.js";
function clear(props)
{
config.setDefaults();
return;
}
...
The compiler error message is:
settings is imported by companion/config.js, but could not be resolved
Did anybody have some hints?
Best regards,
Grizzi
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.
Hello!
I'm having the same trouble, too.
I encountered this in a project I'm currently working it. To make sure I didn't mess it up by myself, I started a blank project and gave it try. It resulted in the same issue.
In first place I created the blank starter project and put this code in the app/index.js:
import { settingsStorage } from "settings";
settingsStorage.setItem("myKey", "test");
console.log("App code started");Which results in:
settings is imported by app/index.js, but could not be resolved Build failed.
After that I tried what @JonFitbit suggested and put it into the /common-folder:
app/index.js:
import Test from "../common/test"
console.log("App code started");
let test = new Test();
test.retrieveValue();common/test.js:
import { settingsStorage } from "settings";
export default class Test {
constructor() {
settingsStorage.setItem("myKey", "test");
}
retrieveValue() {
console.log(settingsStorage.getItem("myKey"));
}
}
And the build fails again:
settings is imported by common/test.js, but could not be resolved
What am I doing wrong? I don't get it. ![]()
Thanks!
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.
and put this code in the app/index.js:
import { settingsStorage } from "settings"; settingsStorage.setItem("myKey", "test"); console.log("App code started");Which results in:
settings is imported by app/index.js, but could not be resolved Build failed.
settingsStorage is part of the companion api, not the device api. It can only be used in the companion/index.js file.
Take a look at the settings guide https://dev.fitbit.com/build/guides/settings/
and the Moment example https://github.com/Fitbit/sdk-moment
Suspect I'm completely misunderstanding the architecture of the APIs here, but does this mean it's not possible to access settings in the app?
What if I want to use a setting in my clock.onTick() section?
Best AnswerYou can't DIRECTLY access settings from the watch app, so you're on the right track. You have to use messaging or file transfer to send settings from companion to watch.
Best AnswerThanks for that.
So I get that I would use messaging in the case where a user changes the settings in the app - to send the new setting to the app.
But I'm trying to format date/time based on user setting so I want to check what's in the settings on each clock.onTick(). Are you saying that I would write those settings to a file to be able to check them at any given point in the app?
Best AnswerAre you talking about changing settings in the .jsx bit of your app, or other settings in the Fitbit app (eg, 12/24-hour time display formatting)?
You don't need settings to be stored in a file on the watch to be able to access them in onTick(). Variables will do. But you'll probably want to store them in a file on the watch so you can reinitialise the variables if the user restarts your clockface.
I think there's a sample of all this somewhere; it might be here.
Best AnswerYes, I'm talking about settings set in the .jsx.
So the use case would be:
- Set a setting in app on phone.It's a <Toggle/> selector that will have a boolean value.
- Refer to that setting in onTick() section of app.
Happy to refer to variable in the app - just can't work out where to get the value from.
I've looked at that example app that you posted but couldn't quite see where it does this.
Best AnswerYou've left a lot of steps out of your outline.
This ignores the desirability of saving and restoring settings on the clockface to streamline restarts.