Skip to main content
Version: v2

Settings Storage API

The settingsStorage API can store data persistently in the Zepp App.

tip

Both the "Side Service" and the "Settings App" can access the data stored via settingsStorage.

The event system of settingsStorage can be used to communicate between the two ends.

For the communication method, please refer to the Overall Architecture

setItem

Storing key-value pairs.

Type

(key: string, value: string) => void

getItem

Get the stored value by key name.

Type

(key: string) => result: string

Code example

settings.settingsStorage.setItem('key', 'Hello World')
const result = settings.settingsStorage.getItem('key')

length: number

settings.settingsStorage.length returns the number of members in settingsStorage

removeItem

Delete the value stored by the key name.

Type

(key: string) => void

clear

Delete all key-value pairs.

() => void

toObject

Converts the content stored in settingsStorage to the form of an object.

Type

() => Record<string, any>

Code example

const storageObj = settings.settingsStorage.toObject()

console.log(storageObj)

addListener

caution

This API only needs to be used in the Side Service. The Settings App is "responsive" to data changes in settingsStorage, so there is no need to manually listen for data changes.

Listens for changes to storage, with the agreed event name change, and can be used in the Side Service to listen for changes to data in settingsStorage by the Settings App.

Code example

settings.settingsStorage.addListener('change', async ({ key, newValue, oldValue }) => {
if (key === 'token' && newValue) {
// ...
await reLogin()
}
})