Skip to main content

Key-value Storage(IOS)

info

NSUbiquitousKeyValueStore:

  • Key-value storage will always be available even if user not logged in icloud.
  • Changes of the key-value store object are initially held in memory, then written to disk by the system at appropriate times.

kvSync

APPLE-DOC: This method will call synchronize() to explicitly synchronizes in-memory keys and values with those stored on disk. The only recommended time to call this method is upon app launch, or upon returning to the foreground, to ensure that the in-memory key-value store representation is up-to-date.

function kvSync(): Promise<void>

kvSetItem

function kvSetItem(
key: string,
value: string
): Promise<void>

kvGetItem

function kvGetItem(
key: string,
): Promise<string | undefined>

kvRemoveItem

function kvRemoveItem(
key: string,
): Promise<void>

kvGetAllItems

function kvGetAllItems(): Promise<Record<string, string>>

onICloudKVStoreRemoteChanged (event)

APPLE-DOC: This notification is sent only upon a change received from iCloud; it is not sent when your app sets a value.

const App = () => {
useEffect(() => {
const ev = CloudStore.onICloudKVStoreRemoteChange(u => {
console.log('onICloudKVStoreRemoteChange:', u);
});
return () => {
ev.remove()
}
}, [])

return null
}