Capacitor Preferences

Store data via Capacitor Preferences API on mobile devices or local storage on the web.

Read more in capacitorjs.com/docs/apis/preferences.

#Usage

Driver name: capacitor-preferences

Install and sync @capacitor/preferences in your Capacitor project:

npm i @capacitor/preferences
npx cap sync
import { createStorage } from "unstorage";
import capacitorPreferences from "unstorage/drivers/capacitor-preferences";

const storage = createStorage({
  driver: capacitorPreferences({
    base: "test",
  }),
});

Options:

  • base: Prefixes all keys to avoid collisions.
  • lib: An imported @capacitor/preferences module or a function that returns it.