Storage API
Storage API
Saves and retrieves data in device local storage.
Note: Storage is managed internally by the SDK and automatically synchronizes data when the app goes to the background or is terminated.
Asynchronous API
SetStorage(key, data, onSuccess, onFail)
Saves data to local storage.
Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
key | string | ✅ | Key to save |
data | string | ✅ | Data to save |
onSuccess | Action<SetStorageResult> | - | Success callback |
onFail | Action<string> | - | Failure callback |
TudadaSDK.Instance.SetStorage("playerName", "Player1",
onSuccess: (result) => Debug.Log("Save complete"),
onFail: (err) => Debug.LogError("Save failed: " + err)
);
GetStorage(key, onSuccess, onFail)
Retrieves data from local storage.
Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
key | string | ✅ | Key to retrieve |
onSuccess | Action<GetStorageResult> | - | Success callback |
onFail | Action<string> | - | Failure callback |
Success Response (GetStorageResult):
| Field | Type | Description |
|---|---|---|
data | string | Retrieved data |
TudadaSDK.Instance.GetStorage("playerName",
onSuccess: (result) => Debug.Log("Name: " + result.data),
onFail: (err) => Debug.LogError("Query failed: " + err)
);
RemoveStorage(key, onSuccess, onFail)
Deletes data from local storage.
Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
key | string | ✅ | Key to delete |
onSuccess | Action<RemoveStorageResult> | - | Success callback |
onFail | Action<string> | - | Failure callback |
TudadaSDK.Instance.RemoveStorage("tempData",
onSuccess: (result) => Debug.Log("Delete complete")
);
ClearStorage(onSuccess, onFail)
Deletes all data from local storage.
Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
onSuccess | Action<ClearStorageResult> | - | Success callback |
onFail | Action<string> | - | Failure callback |
TudadaSDK.Instance.ClearStorage(
onSuccess: (result) => Debug.Log("Clear complete")
);
Synchronous API
SetStorageSync(key, data)
Synchronously saves data to local storage.
Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
key | string | ✅ | Key to save |
data | string | ✅ | Data to save |
TudadaSDK.Instance.SetStorageSync("score", "1000");
GetStorageSync(key)
Synchronously retrieves data from local storage.
Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
key | string | ✅ | Key to retrieve |
Return Value (string):
Returns the retrieved data string.
string score = TudadaSDK.Instance.GetStorageSync("score");
Debug.Log("Score: " + score);
RemoveStorageSync(key)
Synchronously deletes data from local storage.
Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
key | string | ✅ | Key to delete |
TudadaSDK.Instance.RemoveStorageSync("tempData");
ClearStorageSync()
Synchronously deletes all data from local storage.
TudadaSDK.Instance.ClearStorageSync();
GetStorageInfoSync()
Synchronously retrieves storage usage information.
Return Value (StorageInfo):
| Field | Type | Description |
|---|---|---|
keys | string[] | List of stored keys |
currentSize | int | Used capacity (KB) |
limitSize | int | Maximum capacity (KB) |
StorageInfo info = TudadaSDK.Instance.GetStorageInfoSync();
Debug.Log("Number of stored keys: " + info.keys.Length);
Debug.Log("Used capacity: " + info.currentSize + " KB");
Debug.Log("Limit capacity: " + info.limitSize + " KB");