Fitbit Product Experts Alumni are retired members of the Fitbit Product Expert Program. Learn more
Has anyone managed to get Cluster Storage working for sharing data between 2 apps/clocks?
Can they share an example and confirm that the sharing is done at the watch level.
It should be noted that normally each clock/app has it's own private watch storage which possibly suggests that there must be some public watch storage which can be used for sharing.
Author | ch, passion for improvement.
Answered! Go to the Best Answer.
Best AnswerMaybe:
import * as appClusterStorage from 'app-cluster-storage'
const cluster = appClusterStorage.get('gondwana')
console.log(cluster) // should be [object Object]
cluster.setItem('testKey', 'testValue')
const testVar = cluster.getItem('testKey')
console.log(testVar)I have no way of testing this, since I don't have any relevant watches and I suspect it isn't implemented in the sim.
Do you mean Cluster Storage? If so, the data would be shared among multiple apps/clock faces via smartphone. I'm sorry I don't have its working example though.
Best Answer
Fitbit Product Experts Alumni are retired members of the Fitbit Product Expert Program. Learn more
Thanks @r.b - I do mean App Cluster storage.- when I tested it a while back there was no success.
In the package.json permission was requested and the following included
"requestedPermissions": [
"access_app_cluster_storage"
],
"appClusterID": "public",
"developerID": "<your developerID>"
but it doesn't seems to help - the instruction won't build as it has a syntax error
And no means is given to set the storage.
There seems also to be a confusion as to whether this is a companion feature, some say it is a watch storage and others a phone storage.
You probably need some import too like
import { appClusterStorage } from "app-cluster-storage";
But even then appClusterStorage is undefined.
Anybody have any ideas to try?
Author | ch, passion for improvement.
Best AnswerTwo quick thoughts that probably won't help:
Re app-cluster-storage.get(clusterID: "public"), I know where you got that from. In JS, hyphens are subtraction so that's a documentation error.
Best AnswerMaybe:
import * as appClusterStorage from 'app-cluster-storage'
const cluster = appClusterStorage.get('gondwana')
console.log(cluster) // should be [object Object]
cluster.setItem('testKey', 'testValue')
const testVar = cluster.getItem('testKey')
console.log(testVar)I have no way of testing this, since I don't have any relevant watches and I suspect it isn't implemented in the sim.
Fitbit Product Experts Alumni are retired members of the Fitbit Product Expert Program. Learn more
Bingo! It works within an App.
This confirms it is on watch storage and no need for the companion and phone storage.
Curiously it causes the simulator to crash the watch, instead of not working.
Thank you, you are a Star!
Author | ch, passion for improvement.
Fitbit Product Experts Alumni are retired members of the Fitbit Product Expert Program. Learn more
@Gondwana- do you think appClusterStorage has something like appClusterStorage.addEventListener("change", () => {}); ?
It raises an error in the Simulator, may be only because cluster storage is not properly implemented or the syntax is wrong.
Hopefully there is some way of seeing if a change has been made to the storage?
Author | ch, passion for improvement.
Best AnswerI don't think Device SDK in sim implements cluster storage. Try a real watch. I can't because I don't have any left.
Best Answer
Fitbit Product Experts Alumni are retired members of the Fitbit Product Expert Program. Learn more
You could try setting .onchange directly. Total guess...
Best Answer
Fitbit Product Experts Alumni are retired members of the Fitbit Product Expert Program. Learn more
appClusterStorage.onchange = function() {
console.log(` detected a change.`);}
Doesn't get triggered when a change is made in the same app.
Author | ch, passion for improvement.
Best AnswerIt's possible that it doesn't implement the LiveStorage interface.
But have you verified that your appClusterStorage var is of the right type? Eg, does it respond correctly to .setItem(), etc?
Best Answer
Fitbit Product Experts Alumni are retired members of the Fitbit Product Expert Program. Learn more
Yes it's working fine, but it means testing values to see if they change, so looking for a way to trap the change to improve it.
Author | ch, passion for improvement.
Best AnswerIf you can't attach an eventListener, why not wrap the update in a function checking the getItem against newValue after having set?
Best Answer@SunsetRunnergot me thinking about this...
Since only one app can be running at any one time, an app should only need to check for changes made by other apps when it starts. App B can't change storage while App A is running. Internally, App A can communicate its own storage changes using other means. So it may not be necessary for cluster storage to have change events on the device.
I probably didn't explain this well, and I could be wrong.
Best Answer