App Storage
Use Storage.app for persistent storage that survives app restarts and is shared across all web content in the app.
Introduction
Storage.app provides a unified storage API that uses native platform storage when available, with automatic fallback to localStorage in older app versions.
This makes it ideal for storing app state, user preferences, and other data that should persist across sessions and be accessible from any web content rendered in the app regardless of domain.
Where to find: startiapp.Storage.app
Key Characteristics
- Shared across domains - Data is accessible from any web content in the app
- Persists across restarts - Data survives app restarts and updates
- Not encrypted - Do NOT store secrets, passwords, or sensitive data
Storage Limits
- Per value: Up to 256 KB
- Total storage: Up to 50 MB per app installation
When NOT to Use App Storage
Do NOT use Storage.app for:
- Secrets, passwords, or API tokens (use
startiapp.Biometricsinstead) - Large files or binary data
- Sensitive personal information
- Data that needs encryption
Methods
getItem
getItem(key: string): Promise<string | null>
Retrieves a value from storage.
Returns the stored value as a string, or null if the key doesn’t exist.
setItem
setItem(key: string, value: string): Promise<void>
Stores a value in storage.
The value must be a string. For objects, use JSON.stringify() before storing.
removeItem
removeItem(key: string): Promise<void>
Removes a value from storage.
clear
clear(): Promise<void>
Removes all app storage entries.
Note: This only clears data stored through Storage.app, not other localStorage data.
isUsingNativeBridge
isUsingNativeBridge(): boolean
Returns true if using native storage, false if using the localStorage fallback.
Useful for debugging or conditional logic.
Examples
Basic Usage
// Store a value
await startiapp.Storage.app.setItem("theme", "dark");
// Retrieve a value
const theme = await startiapp.Storage.app.getItem("theme");
console.log(theme); // "dark"
// Remove a value
await startiapp.Storage.app.removeItem("theme");
// Clear all app storage data
await startiapp.Storage.app.clear();
Storing Objects
// Store an object (must be serialized)
const userPreferences = {
theme: "dark",
language: "da",
notifications: true
};
await startiapp.Storage.app.setItem("preferences", JSON.stringify(userPreferences));
// Retrieve and parse the object
const stored = await startiapp.Storage.app.getItem("preferences");
if (stored) {
const preferences = JSON.parse(stored);
console.log(preferences.theme); // "dark"
}
Checking for Existing Data
const value = await startiapp.Storage.app.getItem("my-key");
if (value !== null) {
console.log("Found value:", value);
} else {
console.log("No value found, using default");
}
Error Handling
The API is designed to fail silently. Errors are logged but don’t throw exceptions, making it safe to use without try/catch in most cases.
// This will log an error but not throw
await startiapp.Storage.app.setItem("key", "value");
// For critical operations, you can check if native storage is available
if (startiapp.Storage.app.isUsingNativeBridge()) {
console.log("Using native storage");
} else {
console.log("Using localStorage fallback");
}
Fallback Behavior
When the native storage bridge is not available (older app versions or running outside the app), the SDK automatically falls back to using window.localStorage.
This means your code works in both scenarios without changes:
- Updated MAUI apps: Uses native storage
- Older apps: Falls back to localStorage
- Browser testing: Falls back to localStorage
The fallback is completely transparent - you don’t need to check which storage is being used.
Technical Details
Key Namespacing
All keys are internally namespaced with a startiapp: prefix to avoid collisions with other localStorage usage. You don’t need to add this prefix yourself - it’s handled automatically.
For example, when you call:
await startiapp.Storage.app.setItem("theme", "dark");
The actual key stored is startiapp:theme.