Storage API
Storage API
Stores and retrieves data in the device's local storage.
Capacity Limits:
- Maximum per key: 1MB (1024KB)
- Maximum total storage: 10MB (10240KB)
- Only JSON-serializable data is supported
Note: Storage is managed internally by the SDK and automatically syncs data when the app transitions to the background or is terminated.
Async API
setStorage(options)
Stores data in local storage.
Options:
| Parameter | Type | Required | Description |
|---|---|---|---|
key | string | ✅ | Key to store |
data | any | ✅ | Data to store |
success | function | - | Success callback |
fail | function | - | Failure callback |
complete | function | - | Completion callback |
TudadaSDK.setStorage({
key: 'userInfo',
data: { name: 'John', level: 10 },
success: () => console.log('Save complete'),
fail: (err) => console.error('Save failed:', err.errMsg),
});
getStorage(options)
Retrieves data from local storage.
Options:
| Parameter | Type | Required | Description |
|---|---|---|---|
key | string | ✅ | Key to retrieve |
success | function | - | Success callback |
fail | function | - | Failure callback |
complete | function | - | Completion callback |
Success Response:
| Field | Type | Description |
|---|---|---|
data | any | Stored data |
TudadaSDK.getStorage({
key: 'userInfo',
success: (res) => console.log('Data:', res.data),
});
removeStorage(options)
Deletes data from local storage.
Options:
| Parameter | Type | Required | Description |
|---|---|---|---|
key | string | ✅ | Key to delete |
success | function | - | Success callback |
fail | function | - | Failure callback |
complete | function | - | Completion callback |
TudadaSDK.removeStorage({
key: 'tempData',
success: () => console.log('Delete complete'),
});
clearStorage(options?)
Deletes all data from local storage.
Options:
| Parameter | Type | Required | Description |
|---|---|---|---|
success | function | - | Success callback |
fail | function | - | Failure callback |
complete | function | - | Completion callback |
TudadaSDK.clearStorage({
success: () => console.log('Clear complete'),
});
Sync API
setStorageSync(key, data)
Synchronously stores data in local storage.
Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
key | string | ✅ | Key to store |
data | any | ✅ | Data to store |
TudadaSDK.setStorageSync('score', 1000);
// or
TudadaSDK.setStorageSync({ key: 'score', data: 1000 });
getStorageSync(key)
Synchronously retrieves data from local storage.
Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
key | string | ✅ | Key to retrieve |
Return Value:
| Field | Type | Description |
|---|---|---|
| (return value) | any | Stored data (undefined if not found) |
const score = TudadaSDK.getStorageSync('score');
// or
const score = TudadaSDK.getStorageSync({ key: 'score' });
removeStorageSync(key)
Synchronously deletes data from local storage.
Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
key | string | ✅ | Key to delete |
TudadaSDK.removeStorageSync('tempData');
clearStorageSync()
Synchronously deletes all data from local storage.
TudadaSDK.clearStorageSync();
getStorageInfoSync()
Synchronously retrieves storage usage information.
Return Value:
| Field | Type | Description |
|---|---|---|
keys | string[] | List of stored keys |
currentSize | number | Current usage (KB) |
limitSize | number | Maximum capacity (KB) |
const info = TudadaSDK.getStorageInfoSync();
console.log('Stored keys:', info.keys); // ['score', 'userInfo', ...]
console.log('Used space:', info.currentSize, 'KB'); // 12 KB
console.log('Limit:', info.limitSize, 'KB'); // 10240 KB