提交 342ace09 编写于 作者: P PaDaBoo

按照最新API接口说明模板修改

Signed-off-by: NPaDaBoo <xuejianwu@huawei.com>
上级 b73c9f63
......@@ -13,24 +13,19 @@
import data_Preferences from '@ohos.data.preferences'
```
## 系统能力
SystemCapability.DistributedDataManager.Preferences.Core
## 权限
## 属性
| 名称 | 参数类型 | 可读 | 可写 | 说明 |
| -------- | -------- | -------- | -------- | -------- |
| MAX_KEY_LENGTH | string | 是 | 否 | key的最大长度限制,大小为80字节。 |
| MAX_VALUE_LENGTH | string | 是 | 否 | string类型value的最大长度限制,大小为8192字节。 |
| MAX_KEY_LENGTH | string | 是 | 否 | key的最大长度限制,大小为80字节。<br>**系统能力**:SystemCapability.DistributedDataManager.Preferences.Core |
| MAX_VALUE_LENGTH | string | 是 | 否 | string类型value的最大长度限制,大小为8192字节。<br>**系统能力**:SystemCapability.DistributedDataManager.Preferences.Core |
## data_Preferences.getPreferences
### 系统能力
SystemCapability.DistributedDataManager.Preferences.Core
getPreferences(context: Context, name: string, callback: AsyncCallback&lt;Preferences&gt;): void
读取指定文件,将数据加载到Preferences实例,用于数据操作,使用callback形式返回结果。
......@@ -60,6 +55,9 @@ getPreferences(context: Context, name: string, callback: AsyncCallback&lt;Prefer
## data_Preferences.getPreferences
### 系统能力
SystemCapability.DistributedDataManager.Preferences.Core
getPreferences(context: Context, name: string): Promise&lt;Preferences&gt;
读取指定文件,将数据加载到Preferences实例,用于数据操作,使用Promise方式作为异步方法。
......@@ -92,6 +90,9 @@ getPreferences(context: Context, name: string): Promise&lt;Preferences&gt;
## data_Preferences.deletePreferences
### 系统能力
SystemCapability.DistributedDataManager.Preferences.Core
deletePreferences(context: Context, name: string, callback: AsyncCallback&lt;void&gt;)
从内存中移除指定文件对应的Preferences单实例,并删除指定文件及其备份文件、损坏文件。删除指定文件时,应用不允许再使用该实例进行数据操作,否则会出现数据一致性问题,使用callback方式作为异步方法。
......@@ -104,7 +105,7 @@ deletePreferences(context: Context, name: string, callback: AsyncCallback&lt;voi
| callback | AsyncCallback&lt;void&gt; | 是 | 回调函数。 |
- 示例:
```
```
import Ability from '@ohos.application.Ability'
import data_Preferences from '@ohos.data.preferences'
data_Preferences.deletePreferences(this.context, 'mystore', function (err) {
......@@ -119,6 +120,9 @@ deletePreferences(context: Context, name: string, callback: AsyncCallback&lt;voi
## data_Preferences.deletePreferences
### 系统能力
SystemCapability.DistributedDataManager.Preferences.Core
deletePreferences(context: Context, name: string): Promise&lt;void&gt;
从内存中移除指定文件对应的Preferences单实例,并删除指定文件及其备份文件、损坏文件。删除指定文件时,应用不允许再使用该实例进行数据操作,否则会出现数据一致性问题,使用promise方式作为异步方法。
......@@ -149,6 +153,9 @@ deletePreferences(context: Context, name: string): Promise&lt;void&gt;
## data_Preferences.removePreferencesFromCache
### 系统能力
SystemCapability.DistributedDataManager.Preferences.Core
removePreferencesFromCache(context: Context, name: string, callback: AsyncCallback&lt;Preferences&gt;): void
从内存中移除指定文件对应的Preferences单实例。移除Preferences单实例时,应用不允许再使用该实例进行数据操作,否则会出现数据一致性问题。
......@@ -178,6 +185,8 @@ removePreferencesFromCache(context: Context, name: string, callback: AsyncCallba
## data_Preferences.removePreferencesFromCache
### 系统能力 SystemCapability.DistributedDataManager.Preferences.Core
removePreferencesFromCache(context: Context, name: string): Promise&lt;void&gt;
从内存中移除指定文件对应的Preferences单实例。移除Preferences单实例时,应用不允许再使用该实例进行数据操作,否则会出现数据一致性问题。
......@@ -215,6 +224,8 @@ removePreferencesFromCache(context: Context, name: string): Promise&lt;void&gt;
### get
#### 系统能力 SystemCapability.DistributedDataManager.Preferences.Core
get(key: string, defValue: ValueType, callback: AsyncCallback&lt;ValueType&gt;): void
获取键对应的值,如果值为null或者非默认值类型,返回默认数据。
......@@ -242,6 +253,8 @@ get(key: string, defValue: ValueType, callback: AsyncCallback&lt;ValueType&gt;):
### get
#### 系统能力 SystemCapability.DistributedDataManager.Preferences.Core
get(key: string, defValue: ValueType): Promise&lt;ValueType&gt;
获取键对应的值,如果值为null或者非默认值类型,返默认数据。
......@@ -272,6 +285,8 @@ get(key: string, defValue: ValueType): Promise&lt;ValueType&gt;
### put
#### 系统能力 SystemCapability.DistributedDataManager.Preferences.Core
put(key: string, value: ValueType, callback: AsyncCallback&lt;void&gt;): void
首先获取指定文件对应的Preferences实例,然后借助Preferences API将数据写入Preferences实例,通过flush或者flushSync将Preferences实例持久化。
......@@ -299,6 +314,8 @@ put(key: string, value: ValueType, callback: AsyncCallback&lt;void&gt;): void
### put
#### 系统能力 SystemCapability.DistributedDataManager.Preferences.Core
put(key: string, value: ValueType): Promise&lt;void&gt;
首先获取指定文件对应的Preferences实例,然后借助Preferences API将数据写入Preferences实例,通过flush或者flushSync将Preferences实例持久化。
......@@ -329,6 +346,8 @@ put(key: string, value: ValueType): Promise&lt;void&gt;
### has
#### 系统能力 SystemCapability.DistributedDataManager.Preferences.Core
has(key: string, callback: AsyncCallback&lt;boolean&gt;): boolean
检查存储对象是否包含名为给定key的存储。
......@@ -362,6 +381,8 @@ has(key: string, callback: AsyncCallback&lt;boolean&gt;): boolean
### has
#### 系统能力 SystemCapability.DistributedDataManager.Preferences.Core
has(key: string): Promise&lt;boolean&gt;
检查存储对象是否包含名为给定key的存储。
......@@ -393,6 +414,8 @@ has(key: string): Promise&lt;boolean&gt;
### delete
#### 系统能力 SystemCapability.DistributedDataManager.Preferences.Core
delete(key: string, callback: AsyncCallback&lt;void&gt;): void
从存储对象中删除名为给定key的存储。
......@@ -419,6 +442,8 @@ delete(key: string, callback: AsyncCallback&lt;void&gt;): void
### delete
#### 系统能力 SystemCapability.DistributedDataManager.Preferences.Core
delete(key: string): Promise&lt;void&gt;
从存储对象删除名为给定key的存储。
......@@ -448,6 +473,8 @@ delete(key: string): Promise&lt;void&gt;
### flush
#### 系统能力 SystemCapability.DistributedDataManager.Preferences.Core
flush(callback: AsyncCallback&lt;void&gt;): void
将当前preferences对象中的修改保存到当前的preferences,并异步存储到文件中。
......@@ -473,6 +500,8 @@ flush(callback: AsyncCallback&lt;void&gt;): void
### flush
#### 系统能力 SystemCapability.DistributedDataManager.Preferences.Core
flush(): Promise&lt;void&gt;
将当前preferences对象中的修改保存到当前的preferences,并异步存储到文件中。
......@@ -497,6 +526,8 @@ flush(): Promise&lt;void&gt;
### clear
#### 系统能力 SystemCapability.DistributedDataManager.Preferences.Core
clear(callback: AsyncCallback&lt;void&gt;): void
清除此存储对象中的所有存储。
......@@ -522,6 +553,8 @@ clear(callback: AsyncCallback&lt;void&gt;): void
### clear
#### 系统能力 SystemCapability.DistributedDataManager.Preferences.Core
clear(): Promise&lt;void&gt;
清除此存储对象中的所有存储。
......@@ -546,6 +579,8 @@ clear(): Promise&lt;void&gt;
### on('change')
#### 系统能力 SystemCapability.DistributedDataManager.Preferences.Core
on(type: 'change', callback: Callback&lt;{ key : string }&gt;): void
订阅数据变更者类,订阅的key的值发生变更后,在执行flush方法后,callback方法会被回调。
......@@ -569,6 +604,8 @@ on(type: 'change', callback: Callback&lt;{ key : string }&gt;): void
### off('change')
#### 系统能力 SystemCapability.DistributedDataManager.Preferences.Core
off(type: 'change', callback: Callback&lt;{ key : string }&gt;): void
当不再进行订阅数据变更时,使用此接口取消订阅。
......
......@@ -4,7 +4,7 @@
> ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:**
> 从API Version 8开始,该接口不再维护,推荐使用新接口'@ohos.data.preferences'
> 从API Version 8开始,该接口不再维护,推荐使用新接口 [@ohos.data.preferences](js-apis-data-preferences.md)
## 导入模块
......@@ -29,7 +29,7 @@ SystemCapability.DistributedDataManager.Preferences.Core
| MAX_VALUE_LENGTH | string | 是 | 否 | string类型value的最大长度限制,大小为8192字节。 |
## dataStorage.getStorageSync
## dataStorage.getStorageSync<sup>(deprecated) </sup>
getStorageSync(path: string): Storage
......@@ -49,7 +49,7 @@ getStorageSync(path: string): Storage
```
import dataStorage from '@ohos.data.storage'
import featureAbility from '@ohos.ability.featureAbility'
var context = featureAbility.getContext()
var path = await context.getFilesDir()
let storage = dataStorage.getStorageSync(path + '/mystore')
......@@ -58,7 +58,7 @@ getStorageSync(path: string): Storage
```
## dataStorage.getStorage
## dataStorage.getStorage<sup>(deprecated) </sup>
getStorage(path: string, callback: AsyncCallback&lt;Storage&gt;): void
......@@ -74,7 +74,7 @@ getStorage(path: string, callback: AsyncCallback&lt;Storage&gt;): void
```
import dataStorage from '@ohos.data.storage'
import featureAbility from '@ohos.ability.featureAbility'
var context = featureAbility.getContext()
var path = await context.getFilesDir()
dataStorage.getStorage(path + '/mystore', function (err, storage) {
......@@ -88,7 +88,7 @@ getStorage(path: string, callback: AsyncCallback&lt;Storage&gt;): void
```
## dataStorage.getStorage
## dataStorage.getStorage<sup>(deprecated) </sup>
getStorage(path: string): Promise&lt;Storage&gt;
......@@ -108,7 +108,7 @@ getStorage(path: string): Promise&lt;Storage&gt;
```
import dataStorage from '@ohos.data.storage'
import featureAbility from '@ohos.ability.featureAbility'
var context = featureAbility.getContext()
var path = await context.getFilesDir()
let promise = dataStorage.getStorage(path + '/mystore')
......@@ -121,7 +121,7 @@ getStorage(path: string): Promise&lt;Storage&gt;
```
## dataStorage.deleteStorageSync
## dataStorage.deleteStorageSync<sup>(deprecated) </sup>
deleteStorageSync(path: string): void
......@@ -138,7 +138,7 @@ deleteStorageSync(path: string): void
```
## dataStorage.deleteStorage
## dataStorage.deleteStorage<sup>(deprecated) </sup>
deleteStorage(path: string, callback: AsyncCallback&lt;void&gt;)
......@@ -162,7 +162,7 @@ deleteStorage(path: string, callback: AsyncCallback&lt;void&gt;)
```
## dataStorage.deleteStorage
## dataStorage.deleteStorage<sup>(deprecated) </sup>
deleteStorage(path: string): Promise&lt;void&gt;
......@@ -189,7 +189,7 @@ deleteStorage(path: string): Promise&lt;void&gt;
```
## dataStorage.removeStorageFromCacheSync
## dataStorage.removeStorageFromCacheSync<sup>(deprecated) </sup>
removeStorageFromCacheSync(path: string): void
......@@ -208,7 +208,7 @@ removeStorageFromCacheSync(path: string): void
```
## dataStorage.removeStorageFromCache
## dataStorage.removeStorageFromCache<sup>(deprecated) </sup>
removeStorageFromCache(path: string, callback: AsyncCallback&lt;Storage&gt;): void
......@@ -234,7 +234,7 @@ removeStorageFromCache(path: string, callback: AsyncCallback&lt;Storage&gt;): vo
```
## dataStorage.removeStorageFromCache
## dataStorage.removeStorageFromCache<sup>(deprecated) </sup>
removeStorageFromCache(path: string): Promise&lt;void&gt;
......@@ -263,12 +263,12 @@ removeStorageFromCache(path: string): Promise&lt;void&gt;
```
## Storage
## Storage<sup>(deprecated) </sup>
提供获取和修改存储数据的接口。
### getSync
### getSync<sup>(deprecated) </sup>
getSync(key: string, defValue: ValueType): ValueType
......@@ -294,7 +294,7 @@ getSync(key: string, defValue: ValueType): ValueType
```
### get
### get<sup>(deprecated) </sup>
get(key: string, defValue: ValueType, callback: AsyncCallback&lt;ValueType&gt;): void
......@@ -321,7 +321,7 @@ get(key: string, defValue: ValueType, callback: AsyncCallback&lt;ValueType&gt;):
```
### get
### get<sup>(deprecated) </sup>
get(key: string, defValue: ValueType): Promise&lt;ValueType&gt;
......@@ -351,7 +351,7 @@ get(key: string, defValue: ValueType): Promise&lt;ValueType&gt;
```
### putSync
### putSync<sup>(deprecated) </sup>
putSync(key: string, value: ValueType): void
......@@ -371,7 +371,7 @@ putSync(key: string, value: ValueType): void
```
### put
### put<sup>(deprecated) </sup>
put(key: string, value: ValueType, callback: AsyncCallback&lt;void&gt;): void
......@@ -398,7 +398,7 @@ put(key: string, value: ValueType, callback: AsyncCallback&lt;void&gt;): void
```
### put
### put<sup>(deprecated) </sup>
put(key: string, value: ValueType): Promise&lt;void&gt;
......@@ -428,7 +428,7 @@ put(key: string, value: ValueType): Promise&lt;void&gt;
```
### hasSync
### hasSync<sup>(deprecated) </sup>
hasSync(key: string): boolean
......@@ -455,7 +455,7 @@ hasSync(key: string): boolean
```
### has
### has<sup>(deprecated) </sup>
has(key: string, callback: AsyncCallback&lt;boolean&gt;): boolean
......@@ -488,7 +488,7 @@ has(key: string, callback: AsyncCallback&lt;boolean&gt;): boolean
```
### has
### has<sup>(deprecated) </sup>
has(key: string): Promise&lt;boolean&gt;
......@@ -519,7 +519,7 @@ has(key: string): Promise&lt;boolean&gt;
```
### deleteSync
### deleteSync<sup>(deprecated) </sup>
deleteSync(key: string): void
......@@ -538,7 +538,7 @@ deleteSync(key: string): void
```
### delete
### delete<sup>(deprecated) </sup>
delete(key: string, callback: AsyncCallback&lt;void&gt;): void
......@@ -564,7 +564,7 @@ delete(key: string, callback: AsyncCallback&lt;void&gt;): void
```
### delete
### delete<sup>(deprecated) </sup>
delete(key: string): Promise&lt;void&gt;
......@@ -593,7 +593,7 @@ delete(key: string): Promise&lt;void&gt;
```
### flushSync
### flushSync<sup>(deprecated) </sup>
flushSync(): void
......@@ -607,7 +607,7 @@ flushSync(): void
```
### flush
### flush<sup>(deprecated) </sup>
flush(callback: AsyncCallback&lt;void&gt;): void
......@@ -632,7 +632,7 @@ flush(callback: AsyncCallback&lt;void&gt;): void
```
### flush
### flush<sup>(deprecated) </sup>
flush(): Promise&lt;void&gt;
......@@ -656,7 +656,7 @@ flush(): Promise&lt;void&gt;
```
### clearSync
### clearSync<sup>(deprecated) </sup>
clearSync(): void
......@@ -670,7 +670,7 @@ clearSync(): void
```
### clear
### clear<sup>(deprecated) </sup>
clear(callback: AsyncCallback&lt;void&gt;): void
......@@ -695,7 +695,7 @@ clear(callback: AsyncCallback&lt;void&gt;): void
```
### clear
### clear<sup>(deprecated) </sup>
clear(): Promise&lt;void&gt;
......@@ -719,7 +719,7 @@ clear(): Promise&lt;void&gt;
```
### on('change')
### on('change')<sup>(deprecated) </sup>
on(type: 'change', callback: Callback&lt;StorageObserver&gt;): void
......@@ -742,7 +742,7 @@ on(type: 'change', callback: Callback&lt;StorageObserver&gt;): void
```
### off('change')
### off('change')<sup>(deprecated) </sup>
off(type: 'change', callback: Callback&lt;StorageObserver&gt;): void
......@@ -763,7 +763,7 @@ off(type: 'change', callback: Callback&lt;StorageObserver&gt;): void
```
## StorageObserver
## StorageObserver<sup>(deprecated) </sup>
| 名称 | 参数类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册