未验证 提交 a2b293c2 编写于 作者: O openharmony_ci 提交者: Gitee

!2142 ohos Handling API interface integrity and consistency

Merge pull request !2142 from PaDaBoo/master
...@@ -15,10 +15,12 @@ import data_Preferences from '@ohos.data.preferences' ...@@ -15,10 +15,12 @@ import data_Preferences from '@ohos.data.preferences'
## 属性 ## 属性
**系统能力**:以下各项对应的系统能力均为SystemCapability.DistributedDataManager.Preferences.Core
| 名称 | 参数类型 | 可读 | 可写 | 说明 | | 名称 | 参数类型 | 可读 | 可写 | 说明 |
| -------- | -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- | -------- |
| MAX_KEY_LENGTH | string | 是 | 否 | key的最大长度限制,大小为80字节。<br>**系统能力**:SystemCapability.DistributedDataManager.Preferences.Core | | MAX_KEY_LENGTH | string | 是 | 否 | key的最大长度限制,大小为80字节。 |
| MAX_VALUE_LENGTH | string | 是 | 否 | string类型value的最大长度限制,大小为8192字节。<br>**系统能力**:SystemCapability.DistributedDataManager.Preferences.Core | | MAX_VALUE_LENGTH | string | 是 | 否 | string类型value的最大长度限制,大小为8192字节。 |
## data_Preferences.getPreferences ## data_Preferences.getPreferences
...@@ -77,8 +79,8 @@ getPreferences(context: Context, name: string): Promise&lt;Preferences&gt; ...@@ -77,8 +79,8 @@ getPreferences(context: Context, name: string): Promise&lt;Preferences&gt;
import Ability from '@ohos.application.Ability' import Ability from '@ohos.application.Ability'
import data_Preferences from '@ohos.data.preferences' import data_Preferences from '@ohos.data.preferences'
var path = this.context.getDataBaseDir() var path = this.context.getDataBaseDir()
let promise = data_Preferences.getPreferences(this.context, 'mystore') let promisePre = data_Preferences.getPreferences(this.context, 'mystore')
promise.then((preferences) => { promisePre.then((preferences) => {
preferences.putSync('startup', 'auto') preferences.putSync('startup', 'auto')
preferences.flushSync() preferences.flushSync()
}).catch((err) => { }).catch((err) => {
...@@ -89,7 +91,7 @@ getPreferences(context: Context, name: string): Promise&lt;Preferences&gt; ...@@ -89,7 +91,7 @@ getPreferences(context: Context, name: string): Promise&lt;Preferences&gt;
## data_Preferences.deletePreferences ## data_Preferences.deletePreferences
deletePreferences(context: Context, name: string, callback: AsyncCallback&lt;void&gt;) deletePreferences(context: Context, name: string, callback: AsyncCallback&lt;void&gt;): void
从内存中移除指定文件对应的Preferences单实例,并删除指定文件及其备份文件、损坏文件。删除指定文件时,应用不允许再使用该实例进行数据操作,否则会出现数据一致性问题,使用callback方式作为异步方法。 从内存中移除指定文件对应的Preferences单实例,并删除指定文件及其备份文件、损坏文件。删除指定文件时,应用不允许再使用该实例进行数据操作,否则会出现数据一致性问题,使用callback方式作为异步方法。
...@@ -139,8 +141,8 @@ deletePreferences(context: Context, name: string): Promise&lt;void&gt; ...@@ -139,8 +141,8 @@ deletePreferences(context: Context, name: string): Promise&lt;void&gt;
``` ```
import Ability from '@ohos.application.Ability' import Ability from '@ohos.application.Ability'
import data_Preferences from '@ohos.data.preferences' import data_Preferences from '@ohos.data.preferences'
let promise = data_Preferences.deletePreferences(this.context, 'mystore') let promisedelPre = data_Preferences.deletePreferences(this.context, 'mystore')
promise.then(() => { promisedelPre.then(() => {
console.info("Deleted successfully.") console.info("Deleted successfully.")
}).catch((err) => { }).catch((err) => {
console.info("Deleted failed with err: " + err) console.info("Deleted failed with err: " + err)
...@@ -150,7 +152,7 @@ deletePreferences(context: Context, name: string): Promise&lt;void&gt; ...@@ -150,7 +152,7 @@ deletePreferences(context: Context, name: string): Promise&lt;void&gt;
## data_Preferences.removePreferencesFromCache ## data_Preferences.removePreferencesFromCache
removePreferencesFromCache(context: Context, name: string, callback: AsyncCallback&lt;Preferences&gt;): void removePreferencesFromCache(context: Context, name: string, callback: AsyncCallback&lt;void&gt;): void
从内存中移除指定文件对应的Preferences单实例。移除Preferences单实例时,应用不允许再使用该实例进行数据操作,否则会出现数据一致性问题。 从内存中移除指定文件对应的Preferences单实例。移除Preferences单实例时,应用不允许再使用该实例进行数据操作,否则会出现数据一致性问题。
...@@ -163,7 +165,7 @@ removePreferencesFromCache(context: Context, name: string, callback: AsyncCallba ...@@ -163,7 +165,7 @@ removePreferencesFromCache(context: Context, name: string, callback: AsyncCallba
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| context | Context | 是 | 应用程序或功能的上下文 | | context | Context | 是 | 应用程序或功能的上下文 |
| name | string | 是 | 应用程序内部数据存储名称。 | | name | string | 是 | 应用程序内部数据存储名称。 |
| callback | AsyncCallback&lt;[Preferences](#preferences)&gt; | 是 | 回调函数。 | | callback | AsyncCallback&lt;void&gt; | 是 | 回调函数。 |
- 示例: - 示例:
``` ```
...@@ -204,8 +206,8 @@ removePreferencesFromCache(context: Context, name: string): Promise&lt;void&gt; ...@@ -204,8 +206,8 @@ removePreferencesFromCache(context: Context, name: string): Promise&lt;void&gt;
``` ```
import Ability from '@ohos.application.Ability' import Ability from '@ohos.application.Ability'
import data_Preferences from '@ohos.data.preferences' import data_Preferences from '@ohos.data.preferences'
let promise = data_Preferences.removePreferencesFromCache(this.context, 'mystore') let promiserevPre = data_Preferences.removePreferencesFromCache(this.context, 'mystore')
promise.then(() => { promiserevPre.then(() => {
console.info("Removed preferences from cache successfully.") console.info("Removed preferences from cache successfully.")
}).catch((err) => { }).catch((err) => {
console.info("Removed preferences from cache failed with err: " + err) console.info("Removed preferences from cache failed with err: " + err)
...@@ -270,8 +272,8 @@ get(key: string, defValue: ValueType): Promise&lt;ValueType&gt; ...@@ -270,8 +272,8 @@ get(key: string, defValue: ValueType): Promise&lt;ValueType&gt;
- 示例: - 示例:
``` ```
let promise = preferences.get('startup', 'default') let promiseget = preferences.get('startup', 'default')
promise.then((value) => { promiseget.then((value) => {
console.info("The value of startup is " + value) console.info("The value of startup is " + value)
}).catch((err) => { }).catch((err) => {
console.info("Get the value of startup failed with err: " + err) console.info("Get the value of startup failed with err: " + err)
...@@ -331,8 +333,8 @@ put(key: string, value: ValueType): Promise&lt;void&gt; ...@@ -331,8 +333,8 @@ put(key: string, value: ValueType): Promise&lt;void&gt;
- 示例: - 示例:
``` ```
let promise = preferences.put('startup', 'auto') let promiseput = preferences.put('startup', 'auto')
promise.then(() => { promiseput.then(() => {
console.info("Put the value of startup successfully.") console.info("Put the value of startup successfully.")
}).catch((err) => { }).catch((err) => {
console.info("Put the value of startup failed with err: " + err) console.info("Put the value of startup failed with err: " + err)
...@@ -397,8 +399,8 @@ has(key: string): Promise&lt;boolean&gt; ...@@ -397,8 +399,8 @@ has(key: string): Promise&lt;boolean&gt;
- 示例: - 示例:
``` ```
let promise = preferences.has('startup') let promisehas = preferences.has('startup')
promise.then((isExist) => { promisehas.then((isExist) => {
if (isExist) { if (isExist) {
console.info("The key of startup is contained.") console.info("The key of startup is contained.")
} }
...@@ -458,8 +460,8 @@ delete(key: string): Promise&lt;void&gt; ...@@ -458,8 +460,8 @@ delete(key: string): Promise&lt;void&gt;
- 示例: - 示例:
``` ```
let promise = preferences.delete('startup') let promisedel = preferences.delete('startup')
promise.then(() => { promisedel.then(() => {
console.info("Deleted startup key successfully.") console.info("Deleted startup key successfully.")
}).catch((err) => { }).catch((err) => {
console.info("Delete startup key failed with err: " + err) console.info("Delete startup key failed with err: " + err)
...@@ -511,8 +513,8 @@ flush(): Promise&lt;void&gt; ...@@ -511,8 +513,8 @@ flush(): Promise&lt;void&gt;
- 示例: - 示例:
``` ```
let promise = preferences.flush() let promiseflush = preferences.flush()
promise.then(() => { promiseflush.then(() => {
console.info("Flushed to file successfully.") console.info("Flushed to file successfully.")
}).catch((err) => { }).catch((err) => {
console.info("Flush to file failed with err: " + err) console.info("Flush to file failed with err: " + err)
...@@ -564,8 +566,8 @@ clear(): Promise&lt;void&gt; ...@@ -564,8 +566,8 @@ clear(): Promise&lt;void&gt;
- 示例: - 示例:
``` ```
let promise = preferences.clear() let promiseclear = preferences.clear()
promise.then(() => { promiseclear.then(() => {
console.info("Cleared to file successfully.") console.info("Cleared to file successfully.")
}).catch((err) => { }).catch((err) => {
console.info("Clear to file failed with err: " + err) console.info("Clear to file failed with err: " + err)
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
> ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:** > ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:**
> 从API Version 9开始,该接口不再维护,推荐使用新接口 [@ohos.data.preferences](js-apis-data-preferences.md) > 本模块首批接口从API version 6开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。<br/>从API Version 9开始,该接口不再维护,推荐使用新接口 [@ohos.data.preferences](js-apis-data-preferences.md)
## 导入模块 ## 导入模块
...@@ -13,25 +13,24 @@ ...@@ -13,25 +13,24 @@
import dataStorage from '@ohos.data.storage' import dataStorage from '@ohos.data.storage'
``` ```
## 系统能力
SystemCapability.DistributedDataManager.Preferences.Core
## 属性 ## 属性
**系统能力**:以下各项对应的系统能力均为SystemCapability.DistributedDataManager.Preferences.Core
| 名称 | 参数类型 | 可读 | 可写 | 说明 | | 名称 | 参数类型 | 可读 | 可写 | 说明 |
| -------- | -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- | -------- |
| MAX_KEY_LENGTH | string | 是 | 否 | key的最大长度限制,大小为80字节。 | | MAX_KEY_LENGTH | string | 是 | 否 | key的最大长度限制,大小为80字节。 |
| MAX_VALUE_LENGTH | string | 是 | 否 | string类型value的最大长度限制,大小为8192字节。 | | MAX_VALUE_LENGTH | string | 是 | 否 | string类型value的最大长度限制,大小为8192字节。 |
## dataStorage.getStorageSync<sup>(deprecated) </sup> ## dataStorage.getStorageSync
getStorageSync(path: string): Storage getStorageSync(path: string): Storage
读取指定文件,将数据加载到Storage实例,用于数据操作,此方法为同步方法。 读取指定文件,将数据加载到Storage实例,用于数据操作,此方法为同步方法。
**系统能力**:SystemCapability.DistributedDataManager.Preferences.Core
- 参数: - 参数:
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
...@@ -55,12 +54,14 @@ getStorageSync(path: string): Storage ...@@ -55,12 +54,14 @@ getStorageSync(path: string): Storage
``` ```
## dataStorage.getStorage<sup>(deprecated) </sup> ## dataStorage.getStorage
getStorage(path: string, callback: AsyncCallback&lt;Storage&gt;): void getStorage(path: string, callback: AsyncCallback&lt;Storage&gt;): void
读取指定文件,将数据加载到Storage实例,用于数据操作,使用callback形式返回结果。 读取指定文件,将数据加载到Storage实例,用于数据操作,使用callback形式返回结果。
**系统能力**:SystemCapability.DistributedDataManager.Preferences.Core
- 参数: - 参数:
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
...@@ -85,12 +86,14 @@ getStorage(path: string, callback: AsyncCallback&lt;Storage&gt;): void ...@@ -85,12 +86,14 @@ getStorage(path: string, callback: AsyncCallback&lt;Storage&gt;): void
``` ```
## dataStorage.getStorage<sup>(deprecated) </sup> ## dataStorage.getStorage
getStorage(path: string): Promise&lt;Storage&gt; getStorage(path: string): Promise&lt;Storage&gt;
读取指定文件,将数据加载到Storage实例,用于数据操作,使用Promise方式作为异步方法。 读取指定文件,将数据加载到Storage实例,用于数据操作,使用Promise方式作为异步方法。
**系统能力**:SystemCapability.DistributedDataManager.Preferences.Core
- 参数: - 参数:
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
...@@ -108,8 +111,8 @@ getStorage(path: string): Promise&lt;Storage&gt; ...@@ -108,8 +111,8 @@ getStorage(path: string): Promise&lt;Storage&gt;
var context = featureAbility.getContext() var context = featureAbility.getContext()
var path = await context.getFilesDir() var path = await context.getFilesDir()
let promise = dataStorage.getStorage(path + '/mystore') let promisegetSt = dataStorage.getStorage(path + '/mystore')
promise.then((storage) => { promisegetSt.then((storage) => {
storage.putSync('startup', 'auto') storage.putSync('startup', 'auto')
storage.flushSync() storage.flushSync()
}).catch((err) => { }).catch((err) => {
...@@ -118,12 +121,14 @@ getStorage(path: string): Promise&lt;Storage&gt; ...@@ -118,12 +121,14 @@ getStorage(path: string): Promise&lt;Storage&gt;
``` ```
## dataStorage.deleteStorageSync<sup>(deprecated) </sup> ## dataStorage.deleteStorageSync
deleteStorageSync(path: string): void deleteStorageSync(path: string): void
从内存中移除指定文件对应的Storage单实例,并删除指定文件及其备份文件、损坏文件。删除指定文件时,应用不允许再使用该实例进行数据操作,否则会出现数据一致性问题,此方法为同步方法。 从内存中移除指定文件对应的Storage单实例,并删除指定文件及其备份文件、损坏文件。删除指定文件时,应用不允许再使用该实例进行数据操作,否则会出现数据一致性问题,此方法为同步方法。
**系统能力**:SystemCapability.DistributedDataManager.Preferences.Core
- 参数: - 参数:
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
...@@ -135,12 +140,14 @@ deleteStorageSync(path: string): void ...@@ -135,12 +140,14 @@ deleteStorageSync(path: string): void
``` ```
## dataStorage.deleteStorage<sup>(deprecated) </sup> ## dataStorage.deleteStorage
deleteStorage(path: string, callback: AsyncCallback&lt;void&gt;) deleteStorage(path: string, callback: AsyncCallback&lt;void&gt;): void
从内存中移除指定文件对应的Storage单实例,并删除指定文件及其备份文件、损坏文件。删除指定文件时,应用不允许再使用该实例进行数据操作,否则会出现数据一致性问题,使用callback方式作为异步方法。 从内存中移除指定文件对应的Storage单实例,并删除指定文件及其备份文件、损坏文件。删除指定文件时,应用不允许再使用该实例进行数据操作,否则会出现数据一致性问题,使用callback方式作为异步方法。
**系统能力**:SystemCapability.DistributedDataManager.Preferences.Core
- 参数: - 参数:
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
...@@ -159,12 +166,14 @@ deleteStorage(path: string, callback: AsyncCallback&lt;void&gt;) ...@@ -159,12 +166,14 @@ deleteStorage(path: string, callback: AsyncCallback&lt;void&gt;)
``` ```
## dataStorage.deleteStorage<sup>(deprecated) </sup> ## dataStorage.deleteStorage
deleteStorage(path: string): Promise&lt;void&gt; deleteStorage(path: string): Promise&lt;void&gt;
从内存中移除指定文件对应的Storage单实例,并删除指定文件及其备份文件、损坏文件。删除指定文件时,应用不允许再使用该实例进行数据操作,否则会出现数据一致性问题,使用promise方式作为异步方法。 从内存中移除指定文件对应的Storage单实例,并删除指定文件及其备份文件、损坏文件。删除指定文件时,应用不允许再使用该实例进行数据操作,否则会出现数据一致性问题,使用promise方式作为异步方法。
**系统能力**:SystemCapability.DistributedDataManager.Preferences.Core
- 参数: - 参数:
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
...@@ -177,8 +186,8 @@ deleteStorage(path: string): Promise&lt;void&gt; ...@@ -177,8 +186,8 @@ deleteStorage(path: string): Promise&lt;void&gt;
- 示例: - 示例:
``` ```
let promise = dataStorage.deleteStorage(path + '/mystore') let promisedelSt = dataStorage.deleteStorage(path + '/mystore')
promise.then(() => { promisedelSt.then(() => {
console.info("Deleted successfully.") console.info("Deleted successfully.")
}).catch((err) => { }).catch((err) => {
console.info("Deleted failed with err: " + err) console.info("Deleted failed with err: " + err)
...@@ -186,7 +195,7 @@ deleteStorage(path: string): Promise&lt;void&gt; ...@@ -186,7 +195,7 @@ deleteStorage(path: string): Promise&lt;void&gt;
``` ```
## dataStorage.removeStorageFromCacheSync<sup>(deprecated) </sup> ## dataStorage.removeStorageFromCacheSync
removeStorageFromCacheSync(path: string): void removeStorageFromCacheSync(path: string): void
...@@ -194,6 +203,8 @@ removeStorageFromCacheSync(path: string): void ...@@ -194,6 +203,8 @@ removeStorageFromCacheSync(path: string): void
此方法为同步方法。 此方法为同步方法。
**系统能力**:SystemCapability.DistributedDataManager.Preferences.Core
- 参数: - 参数:
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
...@@ -205,19 +216,21 @@ removeStorageFromCacheSync(path: string): void ...@@ -205,19 +216,21 @@ removeStorageFromCacheSync(path: string): void
``` ```
## dataStorage.removeStorageFromCache<sup>(deprecated) </sup> ## dataStorage.removeStorageFromCache
removeStorageFromCache(path: string, callback: AsyncCallback&lt;Storage&gt;): void removeStorageFromCache(path: string, callback: AsyncCallback&lt;void&gt;): void
从内存中移除指定文件对应的Storage单实例。移除Storage单实例时,应用不允许再使用该实例进行数据操作,否则会出现数据一致性问题。 从内存中移除指定文件对应的Storage单实例。移除Storage单实例时,应用不允许再使用该实例进行数据操作,否则会出现数据一致性问题。
此方法为异步方法。 此方法为异步方法。
**系统能力**:SystemCapability.DistributedDataManager.Preferences.Core
- 参数: - 参数:
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| path | string | 是 | 应用程序内部数据存储路径。 | | path | string | 是 | 应用程序内部数据存储路径。 |
| callback | AsyncCallback&lt;[Storage](#storage)&gt; | 是 | 回调函数。 | | callback | AsyncCallback&lt;void&gt; | 是 | 回调函数。 |
- 示例: - 示例:
``` ```
...@@ -231,7 +244,7 @@ removeStorageFromCache(path: string, callback: AsyncCallback&lt;Storage&gt;): vo ...@@ -231,7 +244,7 @@ removeStorageFromCache(path: string, callback: AsyncCallback&lt;Storage&gt;): vo
``` ```
## dataStorage.removeStorageFromCache<sup>(deprecated) </sup> ## dataStorage.removeStorageFromCache
removeStorageFromCache(path: string): Promise&lt;void&gt; removeStorageFromCache(path: string): Promise&lt;void&gt;
...@@ -239,6 +252,8 @@ removeStorageFromCache(path: string): Promise&lt;void&gt; ...@@ -239,6 +252,8 @@ removeStorageFromCache(path: string): Promise&lt;void&gt;
此方法为异步方法。 此方法为异步方法。
**系统能力**:SystemCapability.DistributedDataManager.Preferences.Core
- 参数: - 参数:
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
...@@ -251,8 +266,8 @@ removeStorageFromCache(path: string): Promise&lt;void&gt; ...@@ -251,8 +266,8 @@ removeStorageFromCache(path: string): Promise&lt;void&gt;
- 示例: - 示例:
``` ```
let promise = dataStorage.removeStorageFromCache(path + '/mystore') let promiserevSt = dataStorage.removeStorageFromCache(path + '/mystore')
promise.then(() => { promiserevSt.then(() => {
console.info("Removed storage from cache successfully.") console.info("Removed storage from cache successfully.")
}).catch((err) => { }).catch((err) => {
console.info("Removed storage from cache failed with err: " + err) console.info("Removed storage from cache failed with err: " + err)
...@@ -260,12 +275,12 @@ removeStorageFromCache(path: string): Promise&lt;void&gt; ...@@ -260,12 +275,12 @@ removeStorageFromCache(path: string): Promise&lt;void&gt;
``` ```
## Storage<sup>(deprecated) </sup> ## Storage
提供获取和修改存储数据的接口。 提供获取和修改存储数据的接口。
### getSync<sup>(deprecated) </sup> ### getSync
getSync(key: string, defValue: ValueType): ValueType getSync(key: string, defValue: ValueType): ValueType
...@@ -273,6 +288,8 @@ getSync(key: string, defValue: ValueType): ValueType ...@@ -273,6 +288,8 @@ getSync(key: string, defValue: ValueType): ValueType
此方法为同步方法。 此方法为同步方法。
**系统能力**:SystemCapability.DistributedDataManager.Preferences.Core
- 参数: - 参数:
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
...@@ -291,7 +308,7 @@ getSync(key: string, defValue: ValueType): ValueType ...@@ -291,7 +308,7 @@ getSync(key: string, defValue: ValueType): ValueType
``` ```
### get<sup>(deprecated) </sup> ### get
get(key: string, defValue: ValueType, callback: AsyncCallback&lt;ValueType&gt;): void get(key: string, defValue: ValueType, callback: AsyncCallback&lt;ValueType&gt;): void
...@@ -299,6 +316,8 @@ get(key: string, defValue: ValueType, callback: AsyncCallback&lt;ValueType&gt;): ...@@ -299,6 +316,8 @@ get(key: string, defValue: ValueType, callback: AsyncCallback&lt;ValueType&gt;):
此方法为异步方法。 此方法为异步方法。
**系统能力**:SystemCapability.DistributedDataManager.Preferences.Core
- 参数: - 参数:
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
...@@ -318,7 +337,7 @@ get(key: string, defValue: ValueType, callback: AsyncCallback&lt;ValueType&gt;): ...@@ -318,7 +337,7 @@ get(key: string, defValue: ValueType, callback: AsyncCallback&lt;ValueType&gt;):
``` ```
### get<sup>(deprecated) </sup> ### get
get(key: string, defValue: ValueType): Promise&lt;ValueType&gt; get(key: string, defValue: ValueType): Promise&lt;ValueType&gt;
...@@ -326,6 +345,8 @@ get(key: string, defValue: ValueType): Promise&lt;ValueType&gt; ...@@ -326,6 +345,8 @@ get(key: string, defValue: ValueType): Promise&lt;ValueType&gt;
此方法为异步方法。 此方法为异步方法。
**系统能力**:SystemCapability.DistributedDataManager.Preferences.Core
- **参数:** - **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
...@@ -339,8 +360,8 @@ get(key: string, defValue: ValueType): Promise&lt;ValueType&gt; ...@@ -339,8 +360,8 @@ get(key: string, defValue: ValueType): Promise&lt;ValueType&gt;
- 示例: - 示例:
``` ```
let promise = storage.get('startup', 'default') let promiseget = storage.get('startup', 'default')
promise.then((value) => { promiseget.then((value) => {
console.info("The value of startup is " + value) console.info("The value of startup is " + value)
}).catch((err) => { }).catch((err) => {
console.info("Get the value of startup failed with err: " + err) console.info("Get the value of startup failed with err: " + err)
...@@ -348,7 +369,7 @@ get(key: string, defValue: ValueType): Promise&lt;ValueType&gt; ...@@ -348,7 +369,7 @@ get(key: string, defValue: ValueType): Promise&lt;ValueType&gt;
``` ```
### putSync<sup>(deprecated) </sup> ### putSync
putSync(key: string, value: ValueType): void putSync(key: string, value: ValueType): void
...@@ -356,6 +377,8 @@ putSync(key: string, value: ValueType): void ...@@ -356,6 +377,8 @@ putSync(key: string, value: ValueType): void
此方法为同步方法。 此方法为同步方法。
**系统能力**:SystemCapability.DistributedDataManager.Preferences.Core
- 参数: - 参数:
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
...@@ -368,7 +391,7 @@ putSync(key: string, value: ValueType): void ...@@ -368,7 +391,7 @@ putSync(key: string, value: ValueType): void
``` ```
### put<sup>(deprecated) </sup> ### put
put(key: string, value: ValueType, callback: AsyncCallback&lt;void&gt;): void put(key: string, value: ValueType, callback: AsyncCallback&lt;void&gt;): void
...@@ -376,6 +399,8 @@ put(key: string, value: ValueType, callback: AsyncCallback&lt;void&gt;): void ...@@ -376,6 +399,8 @@ put(key: string, value: ValueType, callback: AsyncCallback&lt;void&gt;): void
此方法为异步方法。 此方法为异步方法。
**系统能力**:SystemCapability.DistributedDataManager.Preferences.Core
- 参数: - 参数:
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
...@@ -395,7 +420,7 @@ put(key: string, value: ValueType, callback: AsyncCallback&lt;void&gt;): void ...@@ -395,7 +420,7 @@ put(key: string, value: ValueType, callback: AsyncCallback&lt;void&gt;): void
``` ```
### put<sup>(deprecated) </sup> ### put
put(key: string, value: ValueType): Promise&lt;void&gt; put(key: string, value: ValueType): Promise&lt;void&gt;
...@@ -403,6 +428,8 @@ put(key: string, value: ValueType): Promise&lt;void&gt; ...@@ -403,6 +428,8 @@ put(key: string, value: ValueType): Promise&lt;void&gt;
此方法为异步方法。 此方法为异步方法。
**系统能力**:SystemCapability.DistributedDataManager.Preferences.Core
- 参数: - 参数:
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
...@@ -416,8 +443,8 @@ put(key: string, value: ValueType): Promise&lt;void&gt; ...@@ -416,8 +443,8 @@ put(key: string, value: ValueType): Promise&lt;void&gt;
- 示例: - 示例:
``` ```
let promise = storage.put('startup', 'auto') let promiseput = storage.put('startup', 'auto')
promise.then(() => { promiseput.then(() => {
console.info("Put the value of startup successfully.") console.info("Put the value of startup successfully.")
}).catch((err) => { }).catch((err) => {
console.info("Put the value of startup failed with err: " + err) console.info("Put the value of startup failed with err: " + err)
...@@ -425,7 +452,7 @@ put(key: string, value: ValueType): Promise&lt;void&gt; ...@@ -425,7 +452,7 @@ put(key: string, value: ValueType): Promise&lt;void&gt;
``` ```
### hasSync<sup>(deprecated) </sup> ### hasSync
hasSync(key: string): boolean hasSync(key: string): boolean
...@@ -433,6 +460,8 @@ hasSync(key: string): boolean ...@@ -433,6 +460,8 @@ hasSync(key: string): boolean
此方法为同步方法。 此方法为同步方法。
**系统能力**:SystemCapability.DistributedDataManager.Preferences.Core
- 参数: - 参数:
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
...@@ -452,7 +481,7 @@ hasSync(key: string): boolean ...@@ -452,7 +481,7 @@ hasSync(key: string): boolean
``` ```
### has<sup>(deprecated) </sup> ### has
has(key: string, callback: AsyncCallback&lt;boolean&gt;): boolean has(key: string, callback: AsyncCallback&lt;boolean&gt;): boolean
...@@ -460,6 +489,8 @@ has(key: string, callback: AsyncCallback&lt;boolean&gt;): boolean ...@@ -460,6 +489,8 @@ has(key: string, callback: AsyncCallback&lt;boolean&gt;): boolean
此方法为异步方法。 此方法为异步方法。
**系统能力**:SystemCapability.DistributedDataManager.Preferences.Core
- 参数: - 参数:
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
...@@ -485,7 +516,7 @@ has(key: string, callback: AsyncCallback&lt;boolean&gt;): boolean ...@@ -485,7 +516,7 @@ has(key: string, callback: AsyncCallback&lt;boolean&gt;): boolean
``` ```
### has<sup>(deprecated) </sup> ### has
has(key: string): Promise&lt;boolean&gt; has(key: string): Promise&lt;boolean&gt;
...@@ -493,6 +524,8 @@ has(key: string): Promise&lt;boolean&gt; ...@@ -493,6 +524,8 @@ has(key: string): Promise&lt;boolean&gt;
此方法为异步方法。 此方法为异步方法。
**系统能力**:SystemCapability.DistributedDataManager.Preferences.Core
- 参数: - 参数:
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
...@@ -505,8 +538,8 @@ has(key: string): Promise&lt;boolean&gt; ...@@ -505,8 +538,8 @@ has(key: string): Promise&lt;boolean&gt;
- 示例: - 示例:
``` ```
let promise = storage.has('startup') let promisehas = storage.has('startup')
promise.then((isExist) => { promisehas.then((isExist) => {
if (isExist) { if (isExist) {
console.info("The key of startup is contained.") console.info("The key of startup is contained.")
} }
...@@ -516,7 +549,7 @@ has(key: string): Promise&lt;boolean&gt; ...@@ -516,7 +549,7 @@ has(key: string): Promise&lt;boolean&gt;
``` ```
### deleteSync<sup>(deprecated) </sup> ### deleteSync
deleteSync(key: string): void deleteSync(key: string): void
...@@ -524,6 +557,8 @@ deleteSync(key: string): void ...@@ -524,6 +557,8 @@ deleteSync(key: string): void
此方法为同步方法。 此方法为同步方法。
**系统能力**:SystemCapability.DistributedDataManager.Preferences.Core
- 参数: - 参数:
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
...@@ -535,7 +570,7 @@ deleteSync(key: string): void ...@@ -535,7 +570,7 @@ deleteSync(key: string): void
``` ```
### delete<sup>(deprecated) </sup> ### delete
delete(key: string, callback: AsyncCallback&lt;void&gt;): void delete(key: string, callback: AsyncCallback&lt;void&gt;): void
...@@ -543,6 +578,8 @@ delete(key: string, callback: AsyncCallback&lt;void&gt;): void ...@@ -543,6 +578,8 @@ delete(key: string, callback: AsyncCallback&lt;void&gt;): void
此方法为异步方法。 此方法为异步方法。
**系统能力**:SystemCapability.DistributedDataManager.Preferences.Core
- 参数: - 参数:
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
...@@ -561,7 +598,7 @@ delete(key: string, callback: AsyncCallback&lt;void&gt;): void ...@@ -561,7 +598,7 @@ delete(key: string, callback: AsyncCallback&lt;void&gt;): void
``` ```
### delete<sup>(deprecated) </sup> ### delete
delete(key: string): Promise&lt;void&gt; delete(key: string): Promise&lt;void&gt;
...@@ -569,6 +606,8 @@ delete(key: string): Promise&lt;void&gt; ...@@ -569,6 +606,8 @@ delete(key: string): Promise&lt;void&gt;
此方法为异步方法。 此方法为异步方法。
**系统能力**:SystemCapability.DistributedDataManager.Preferences.Core
- 参数: - 参数:
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
...@@ -581,8 +620,8 @@ delete(key: string): Promise&lt;void&gt; ...@@ -581,8 +620,8 @@ delete(key: string): Promise&lt;void&gt;
- 示例: - 示例:
``` ```
let promise = storage.delete('startup') let promisedel = storage.delete('startup')
promise.then(() => { promisedel.then(() => {
console.info("Deleted startup key successfully.") console.info("Deleted startup key successfully.")
}).catch((err) => { }).catch((err) => {
console.info("Delete startup key failed with err: " + err) console.info("Delete startup key failed with err: " + err)
...@@ -590,7 +629,7 @@ delete(key: string): Promise&lt;void&gt; ...@@ -590,7 +629,7 @@ delete(key: string): Promise&lt;void&gt;
``` ```
### flushSync<sup>(deprecated) </sup> ### flushSync
flushSync(): void flushSync(): void
...@@ -598,13 +637,15 @@ flushSync(): void ...@@ -598,13 +637,15 @@ flushSync(): void
此方法为同步方法。 此方法为同步方法。
**系统能力**:SystemCapability.DistributedDataManager.Preferences.Core
- 示例: - 示例:
``` ```
storage.flushSync() storage.flushSync()
``` ```
### flush<sup>(deprecated) </sup> ### flush
flush(callback: AsyncCallback&lt;void&gt;): void flush(callback: AsyncCallback&lt;void&gt;): void
...@@ -612,6 +653,8 @@ flush(callback: AsyncCallback&lt;void&gt;): void ...@@ -612,6 +653,8 @@ flush(callback: AsyncCallback&lt;void&gt;): void
此方法为异步方法。 此方法为异步方法。
**系统能力**:SystemCapability.DistributedDataManager.Preferences.Core
- 参数: - 参数:
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
...@@ -629,7 +672,7 @@ flush(callback: AsyncCallback&lt;void&gt;): void ...@@ -629,7 +672,7 @@ flush(callback: AsyncCallback&lt;void&gt;): void
``` ```
### flush<sup>(deprecated) </sup> ### flush
flush(): Promise&lt;void&gt; flush(): Promise&lt;void&gt;
...@@ -637,6 +680,8 @@ flush(): Promise&lt;void&gt; ...@@ -637,6 +680,8 @@ flush(): Promise&lt;void&gt;
此方法为异步方法。 此方法为异步方法。
**系统能力**:SystemCapability.DistributedDataManager.Preferences.Core
- 返回值: - 返回值:
| 类型 | 说明 | | 类型 | 说明 |
| -------- | -------- | | -------- | -------- |
...@@ -644,8 +689,8 @@ flush(): Promise&lt;void&gt; ...@@ -644,8 +689,8 @@ flush(): Promise&lt;void&gt;
- 示例: - 示例:
``` ```
let promise = storage.flush() let promiseflush = storage.flush()
promise.then(() => { promiseflush.then(() => {
console.info("Flushed to file successfully.") console.info("Flushed to file successfully.")
}).catch((err) => { }).catch((err) => {
console.info("Flush to file failed with err: " + err) console.info("Flush to file failed with err: " + err)
...@@ -653,7 +698,7 @@ flush(): Promise&lt;void&gt; ...@@ -653,7 +698,7 @@ flush(): Promise&lt;void&gt;
``` ```
### clearSync<sup>(deprecated) </sup> ### clearSync
clearSync(): void clearSync(): void
...@@ -661,13 +706,15 @@ clearSync(): void ...@@ -661,13 +706,15 @@ clearSync(): void
此方法为同步方法。 此方法为同步方法。
**系统能力**:SystemCapability.DistributedDataManager.Preferences.Core
- 示例: - 示例:
``` ```
storage.clearSync() storage.clearSync()
``` ```
### clear<sup>(deprecated) </sup> ### clear
clear(callback: AsyncCallback&lt;void&gt;): void clear(callback: AsyncCallback&lt;void&gt;): void
...@@ -675,6 +722,8 @@ clear(callback: AsyncCallback&lt;void&gt;): void ...@@ -675,6 +722,8 @@ clear(callback: AsyncCallback&lt;void&gt;): void
此方法为异步方法。 此方法为异步方法。
**系统能力**:SystemCapability.DistributedDataManager.Preferences.Core
- 参数: - 参数:
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
...@@ -692,7 +741,7 @@ clear(callback: AsyncCallback&lt;void&gt;): void ...@@ -692,7 +741,7 @@ clear(callback: AsyncCallback&lt;void&gt;): void
``` ```
### clear<sup>(deprecated) </sup> ### clear
clear(): Promise&lt;void&gt; clear(): Promise&lt;void&gt;
...@@ -700,6 +749,8 @@ clear(): Promise&lt;void&gt; ...@@ -700,6 +749,8 @@ clear(): Promise&lt;void&gt;
此方法为异步方法。 此方法为异步方法。
**系统能力**:SystemCapability.DistributedDataManager.Preferences.Core
- 返回值: - 返回值:
| 类型 | 说明 | | 类型 | 说明 |
| -------- | -------- | | -------- | -------- |
...@@ -707,8 +758,8 @@ clear(): Promise&lt;void&gt; ...@@ -707,8 +758,8 @@ clear(): Promise&lt;void&gt;
- 示例: - 示例:
``` ```
let promise = storage.clear() let promiseclear = storage.clear()
promise.then(() => { promiseclear.then(() => {
console.info("Cleared to file successfully.") console.info("Cleared to file successfully.")
}).catch((err) => { }).catch((err) => {
console.info("Clear to file failed with err: " + err) console.info("Clear to file failed with err: " + err)
...@@ -716,12 +767,14 @@ clear(): Promise&lt;void&gt; ...@@ -716,12 +767,14 @@ clear(): Promise&lt;void&gt;
``` ```
### on('change')<sup>(deprecated) </sup> ### on('change')
on(type: 'change', callback: Callback&lt;StorageObserver&gt;): void on(type: 'change', callback: Callback&lt;StorageObserver&gt;): void
订阅数据变更者类需要实现StorageObserver接口,订阅的key的值发生变更后,在执行flush/flushSync方法后,callback方法会被回调。 订阅数据变更者类需要实现StorageObserver接口,订阅的key的值发生变更后,在执行flush/flushSync方法后,callback方法会被回调。
**系统能力**:SystemCapability.DistributedDataManager.Preferences.Core
- 参数: - 参数:
| 参数名 | 类型 | 说明 | | 参数名 | 类型 | 说明 |
| -------- | -------- | -------- | | -------- | -------- | -------- |
...@@ -739,12 +792,14 @@ on(type: 'change', callback: Callback&lt;StorageObserver&gt;): void ...@@ -739,12 +792,14 @@ on(type: 'change', callback: Callback&lt;StorageObserver&gt;): void
``` ```
### off('change')<sup>(deprecated) </sup> ### off('change')
off(type: 'change', callback: Callback&lt;StorageObserver&gt;): void off(type: 'change', callback: Callback&lt;StorageObserver&gt;): void
当不再进行订阅数据变更时,使用此接口取消订阅。 当不再进行订阅数据变更时,使用此接口取消订阅。
**系统能力**:SystemCapability.DistributedDataManager.Preferences.Core
- 参数: - 参数:
| 参数名 | 类型 | 说明 | | 参数名 | 类型 | 说明 |
| -------- | -------- | -------- | | -------- | -------- | -------- |
...@@ -760,7 +815,9 @@ off(type: 'change', callback: Callback&lt;StorageObserver&gt;): void ...@@ -760,7 +815,9 @@ off(type: 'change', callback: Callback&lt;StorageObserver&gt;): void
``` ```
## StorageObserver<sup>(deprecated) </sup> ## StorageObserver
**系统能力**:以下各项对应的系统能力均为SystemCapability.DistributedDataManager.Preferences.Core
| 名称 | 参数类型 | 必填 | 说明 | | 名称 | 参数类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册