提交 05f461c5 编写于 作者: A Annie_wang

update docs

Signed-off-by: NAnnie_wang <annie.wangli@huawei.com>
上级 60e2c639
...@@ -15,7 +15,7 @@ import distributedObject from '@ohos.data.distributedDataObject'; ...@@ -15,7 +15,7 @@ import distributedObject from '@ohos.data.distributedDataObject';
## distributedObject.create<sup>9+</sup> ## distributedObject.create<sup>9+</sup>
create(context: Context, source: object): DistributedObjectV9 create(context: Context, source: object): DataObject
Creates a distributed data object. Creates a distributed data object.
...@@ -25,14 +25,14 @@ Creates a distributed data object. ...@@ -25,14 +25,14 @@ Creates a distributed data object.
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| context | Context | Yes| Application context.<br>For details about the application context of the FA model, see [Context](js-apis-inner-app-context.md).<br>For details about the application context of the stage model, see [Context](js-apis-ability-context.md).| | context | Context | Yes| Application context.<br>For details about the application context of the FA model, see [Context](js-apis-inner-app-context.md).<br>For details about the application context of the stage model, see [Context](js-apis-inner-application-uiAbilityContext.md).|
| source | object | Yes| Attributes of the distributed data object.| | source | object | Yes| Attributes of the distributed data object.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| [DistributedObjectV9](#distributedobjectv9) | Distributed data object created.| | [DataObject](#dataobject) | Distributed data object created.|
**Example** **Example**
...@@ -55,15 +55,14 @@ Stage model: ...@@ -55,15 +55,14 @@ Stage model:
import distributedObject from '@ohos.data.distributedDataObject'; import distributedObject from '@ohos.data.distributedDataObject';
import UIAbility from '@ohos.app.ability.UIAbility'; import UIAbility from '@ohos.app.ability.UIAbility';
// Obtain the context. let g_object = null;
let context;
class EntryAbility extends UIAbility { class EntryAbility extends UIAbility {
onWindowStageCreate(windowStage){ onWindowStageCreate(windowStage){
context = this.context // Create a distributed data object, which has attributes of the string, number, boolean, and object types.
g_object = distributedObject.create(this.context, {name:"Amy", age:18, isVis:false, parent:{mother:"jack mom",father:"jack Dad"}});
} }
} }
// Create a distributed data object, which contains attributes of the string, number, boolean, and object types.
let g_object = distributedObject.create(context, {name:"Amy", age:18, isVis:false, parent:{mother:"jack mom",father:"jack Dad"}});
``` ```
## distributedObject.genSessionId ## distributedObject.genSessionId
...@@ -109,9 +108,9 @@ Called when the **revokeSave()** API is successfully called. ...@@ -109,9 +108,9 @@ Called when the **revokeSave()** API is successfully called.
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| sessionId | string | Yes| Unique ID for multi-device collaboration.| | sessionId | string | Yes| Unique ID for multi-device collaboration.|
## DistributedObjectV9 ## DataObject
Provides APIs for managing a distributed data object. Provides APIs for managing a distributed data object. Before using any API of this class, use [create()](#distributedobjectcreate9) to create a **DataObject** object.
### setSessionId<sup>9+</sup> ### setSessionId<sup>9+</sup>
...@@ -132,7 +131,7 @@ Sets a session ID for synchronization. Automatic synchronization is performed fo ...@@ -132,7 +131,7 @@ Sets a session ID for synchronization. Automatic synchronization is performed fo
**Error codes** **Error codes**
For details about the error codes, see [Distributed Data Object Error Codes] (../errorcodes/errorcode-distributed-dataObject.md). For details about the error codes, see [Distributed Data Object Error Codes](../errorcodes/errorcode-distributed-dataObject.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -140,36 +139,10 @@ Sets a session ID for synchronization. Automatic synchronization is performed fo ...@@ -140,36 +139,10 @@ Sets a session ID for synchronization. Automatic synchronization is performed fo
**Example** **Example**
FA model:
```js ```js
import distributedObject from '@ohos.data.distributedDataObject';
import featureAbility from '@ohos.ability.featureAbility';
// Obtain the context.
let context = featureAbility.getContext();
let g_object = distributedObject.create(context, {name:"Amy", age:18, isVis:false, parent:{mother:"jack mom",father:"jack Dad"}});
// Add g_object to the distributed network.
g_object.setSessionId(distributedObject.genSessionId(), ()=>{
console.log("join session");
});
```
Stage model:
```ts
import distributedObject from '@ohos.data.distributedDataObject';
import UIAbility from '@ohos.app.ability.UIAbility';
// Obtain the context.
let context;
class EntryAbility extends UIAbility {
onWindowStageCreate(windowStage){
context = this.context
}
}
let g_object = distributedObject.create(context, {name:"Amy", age:18, isVis:false, parent:{mother:"jack mom",father:"jack Dad"}});
// Add g_object to the distributed network. // Add g_object to the distributed network.
g_object.setSessionId(distributedObject.genSessionId(), ()=>{ g_object.setSessionId(distributedObject.genSessionId(), ()=>{
console.log("join session"); console.info("join session");
}); });
``` ```
...@@ -191,7 +164,7 @@ Exits all joined sessions. ...@@ -191,7 +164,7 @@ Exits all joined sessions.
**Error codes** **Error codes**
For details about the error codes, see [Distributed Data Object Error Codes] (../errorcodes/errorcode-distributed-dataObject.md). For details about the error codes, see [Distributed Data Object Error Codes](../errorcodes/errorcode-distributed-dataObject.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -199,44 +172,14 @@ Exits all joined sessions. ...@@ -199,44 +172,14 @@ Exits all joined sessions.
**Example** **Example**
FA model:
```js ```js
import distributedObject from '@ohos.data.distributedDataObject';
import featureAbility from '@ohos.ability.featureAbility';
// Obtain the context.
let context = featureAbility.getContext();
let g_object = distributedObject.create(context, {name:"Amy", age:18, isVis:false, parent:{mother:"jack mom",father:"jack Dad"}});
// Add g_object to the distributed network. // Add g_object to the distributed network.
g_object.setSessionId(distributedObject.genSessionId(), ()=>{ g_object.setSessionId(distributedObject.genSessionId(), ()=>{
console.log("join session"); console.info("join session");
}); });
// Exit the distributed network. // Exit the distributed network.
g_object.setSessionId(() => { g_object.setSessionId(() => {
console.log("leave all lession."); console.info("leave all lession.");
});
```
Stage model:
```ts
import distributedObject from '@ohos.data.distributedDataObject';
import UIAbility from '@ohos.app.ability.UIAbility';
// Obtain the context.
let context;
class EntryAbility extends UIAbility {
onWindowStageCreate(windowStage){
context = this.context
}
}
let g_object = distributedObject.create(context, {name:"Amy", age:18, isVis:false, parent:{mother:"jack mom",father:"jack Dad"}});
// Add g_object to the distributed network.
g_object.setSessionId(distributedObject.genSessionId(), ()=>{
console.log("join session");
});
// Exit the distributed network.
g_object.setSessionId(() => {
console.log("leave all lession.");
}); });
``` ```
...@@ -264,7 +207,7 @@ Sets a session ID for synchronization. Automatic synchronization is performed fo ...@@ -264,7 +207,7 @@ Sets a session ID for synchronization. Automatic synchronization is performed fo
**Error codes** **Error codes**
For details about the error codes, see [Distributed Data Object Error Codes] (../errorcodes/errorcode-distributed-dataObject.md). For details about the error codes, see [Distributed Data Object Error Codes](../errorcodes/errorcode-distributed-dataObject.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -272,41 +215,7 @@ Sets a session ID for synchronization. Automatic synchronization is performed fo ...@@ -272,41 +215,7 @@ Sets a session ID for synchronization. Automatic synchronization is performed fo
**Example** **Example**
FA model:
```js ```js
import distributedObject from '@ohos.data.distributedDataObject';
import featureAbility from '@ohos.ability.featureAbility';
// Obtain the context.
let context = featureAbility.getContext();
let g_object = distributedObject.create(context, {name:"Amy", age:18, isVis:false, parent:{mother:"jack mom",father:"jack Dad"}});
// Add g_object to the distributed network.
g_object.setSessionId(distributedObject.genSessionId()).then (()=>{
console.log("join session.");
}).catch((error)=>{
console.info("error:" + error.code + error.message);
});
// Exit the distributed network.
g_object.setSessionId().then (()=>{
console.log("leave all lession.");
}).catch((error)=>{
console.info("error:" + error.code + error.message);
});
```
Stage model:
```ts
import distributedObject from '@ohos.data.distributedDataObject';
import UIAbility from '@ohos.app.ability.UIAbility';
// Obtain the context.
let context;
class EntryAbility extends UIAbility {
onWindowStageCreate(windowStage){
context = this.context
}
}
let g_object = distributedObject.create(context, {name:"Amy", age:18, isVis:false, parent:{mother:"jack mom",father:"jack Dad"}});
// Add g_object to the distributed network. // Add g_object to the distributed network.
g_object.setSessionId(distributedObject.genSessionId()).then (()=>{ g_object.setSessionId(distributedObject.genSessionId()).then (()=>{
console.info("join session."); console.info("join session.");
...@@ -315,7 +224,7 @@ g_object.setSessionId(distributedObject.genSessionId()).then (()=>{ ...@@ -315,7 +224,7 @@ g_object.setSessionId(distributedObject.genSessionId()).then (()=>{
}); });
// Exit the distributed network. // Exit the distributed network.
g_object.setSessionId().then (()=>{ g_object.setSessionId().then (()=>{
console.log("leave all lession."); console.info("leave all lession.");
}).catch((error)=>{ }).catch((error)=>{
console.info("error:" + error.code + error.message); console.info("error:" + error.code + error.message);
}); });
...@@ -338,39 +247,7 @@ Subscribes to data changes of this distributed data object. ...@@ -338,39 +247,7 @@ Subscribes to data changes of this distributed data object.
**Example** **Example**
FA model:
```js ```js
import distributedObject from '@ohos.data.distributedDataObject';
import featureAbility from '@ohos.ability.featureAbility';
// Obtain the context.
let context = featureAbility.getContext();
let g_object = distributedObject.create(context, {name:"Amy", age:18, isVis:false, parent:{mother:"jack mom",father:"jack Dad"}});
globalThis.changeCallback = (sessionId, changeData) => {
console.info("change" + sessionId);
if (changeData != null && changeData != undefined) {
changeData.forEach(element => {
console.info("changed !" + element + " " + g_object[element]);
});
}
}
g_object.on("change", globalThis.changeCallback);
```
Stage model:
```ts
import distributedObject from '@ohos.data.distributedDataObject';
import UIAbility from '@ohos.app.ability.UIAbility';
// Obtain the context.
let context;
class EntryAbility extends UIAbility {
onWindowStageCreate(windowStage){
context = this.context
}
}
let g_object = distributedObject.create(context, {name:"Amy", age:18, isVis:false, parent:{mother:"jack mom",father:"jack Dad"}});
globalThis.changeCallback = (sessionId, changeData) => { globalThis.changeCallback = (sessionId, changeData) => {
console.info("change" + sessionId); console.info("change" + sessionId);
if (changeData != null && changeData != undefined) { if (changeData != null && changeData != undefined) {
...@@ -394,40 +271,13 @@ Unsubscribes from the data changes of this distributed data object. ...@@ -394,40 +271,13 @@ Unsubscribes from the data changes of this distributed data object.
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| type | string | Yes| Event type to unsubscribe from. The value is **change**, which indicates data changes. | | type | string | Yes| Event type to unsubscribe from. The value is **change**, which indicates data changes.|
| callback | Callback<{ sessionId: string, fields: Array&lt;string&gt; }> | No| Callback for data changes. If this parameter is not specified, all data change callbacks of this distributed data object will be unregistered.<br>**sessionId** indicates the session ID of the distributed data object.<br>**fields** indicates the changed attributes of the distributed data object.| | callback | Callback<{ sessionId: string, fields: Array&lt;string&gt; }> | No| Callback for data changes. If this parameter is not specified, all data change callbacks of this distributed data object will be unregistered.<br>**sessionId** indicates the session ID of the distributed data object.<br>**fields** indicates the changed attributes of the distributed data object.|
**Example** **Example**
FA model:
```js ```js
import distributedObject from '@ohos.data.distributedDataObject';
import featureAbility from '@ohos.ability.featureAbility';
// Obtain the context.
let context = featureAbility.getContext();
let g_object = distributedObject.create(context, {name:"Amy", age:18, isVis:false, parent:{mother:"jack mom",father:"jack Dad"}});
// Unregister the specified data change callback.
g_object.off("change", globalThis.changeCallback);
// Unregister all data change callbacks.
g_object.off("change");
```
Stage model:
```ts
import distributedObject from '@ohos.data.distributedDataObject';
import UIAbility from '@ohos.app.ability.UIAbility';
// Obtain the context.
let context;
class EntryAbility extends UIAbility {
onWindowStageCreate(windowStage){
context = this.context
}
}
let g_object = distributedObject.create(context, {name:"Amy", age:18, isVis:false, parent:{mother:"jack mom",father:"jack Dad"}});
// Unregister the specified data change callback. // Unregister the specified data change callback.
g_object.off("change", globalThis.changeCallback); g_object.off("change", globalThis.changeCallback);
// Unregister all data change callbacks. // Unregister all data change callbacks.
...@@ -451,37 +301,10 @@ Subscribes to statue changes of this distributed data object. ...@@ -451,37 +301,10 @@ Subscribes to statue changes of this distributed data object.
**Example** **Example**
FA model:
```js ```js
import distributedObject from '@ohos.data.distributedDataObject';
import featureAbility from '@ohos.ability.featureAbility';
// Obtain the context.
let context = featureAbility.getContext();
globalThis.statusCallback = (sessionId, networkId, status) => {
globalThis.response += "status changed " + sessionId + " " + status + " " + networkId;
}
let g_object = distributedObject.create(context, {name:"Amy", age:18, isVis:false, parent:{mother:"jack mom",father:"jack Dad"}});
g_object.on("status", globalThis.statusCallback);
```
Stage model:
```ts
import distributedObject from '@ohos.data.distributedDataObject';
import UIAbility from '@ohos.app.ability.UIAbility';
// Obtain the context.
let context;
class EntryAbility extends UIAbility {
onWindowStageCreate(windowStage){
context = this.context
}
}
globalThis.statusCallback = (sessionId, networkId, status) => { globalThis.statusCallback = (sessionId, networkId, status) => {
globalThis.response += "status changed " + sessionId + " " + status + " " + networkId; globalThis.response += "status changed " + sessionId + " " + status + " " + networkId;
} }
let g_object = distributedObject.create(context, {name:"Amy", age:18, isVis:false, parent:{mother:"jack mom",father:"jack Dad"}});
g_object.on("status", globalThis.statusCallback); g_object.on("status", globalThis.statusCallback);
``` ```
...@@ -503,37 +326,7 @@ Unsubscribes from the status change of this distributed data object. ...@@ -503,37 +326,7 @@ Unsubscribes from the status change of this distributed data object.
**Example** **Example**
FA model:
```js ```js
import distributedObject from '@ohos.data.distributedDataObject';
import featureAbility from '@ohos.ability.featureAbility';
// Obtain the context.
let context = featureAbility.getContext();
let g_object = distributedObject.create(context, {name:"Amy", age:18, isVis:false, parent:{mother:"jack mom",father:"jack Dad"}});
globalThis.statusCallback = (sessionId, networkId, status) => {
globalThis.response += "status changed " + sessionId + " " + status + " " + networkId;
}
// Unregister the specified status change callback.
g_object.off("status",globalThis.statusCallback);
// Unregister all status change callbacks.
g_object.off("status");
```
Stage model:
```ts
import distributedObject from '@ohos.data.distributedDataObject';
import UIAbility from '@ohos.app.ability.UIAbility';
// Obtain the context.
let context;
class EntryAbility extends UIAbility {
onWindowStageCreate(windowStage){
context = this.context
}
}
let g_object = distributedObject.create(context, {name:"Amy", age:18, isVis:false, parent:{mother:"jack mom",father:"jack Dad"}});
globalThis.statusCallback = (sessionId, networkId, status) => { globalThis.statusCallback = (sessionId, networkId, status) => {
globalThis.response += "status changed " + sessionId + " " + status + " " + networkId; globalThis.response += "status changed " + sessionId + " " + status + " " + networkId;
} }
...@@ -568,38 +361,10 @@ The saved data will be released in the following cases: ...@@ -568,38 +361,10 @@ The saved data will be released in the following cases:
**Example** **Example**
FA model:
```ts ```ts
import distributedObject from '@ohos.data.distributedDataObject';
import featureAbility from '@ohos.ability.featureAbility';
// Obtain the context.
let context = featureAbility.getContext();
let g_object = distributedObject.create(context, {name:"Amy", age:18, isVis:false});
g_object.setSessionId("123456"); g_object.setSessionId("123456");
g_object.save("local", (result) => { g_object.save("local", (result) => {
console.log("save callback"); console.info("save callback");
console.info("save sessionId: " + result.sessionId);
console.info("save version: " + result.version);
console.info("save deviceId: " + result.deviceId);
});
```
Stage model:
```ts
import distributedObject from '@ohos.data.distributedDataObject';
import UIAbility from '@ohos.app.ability.UIAbility';
// Obtain the context.
let context;
class EntryAbility extends UIAbility {
onWindowStageCreate(windowStage){
context = this.context
}
}
let g_object = distributedObject.create(context, {name:"Amy", age:18, isVis:false});
g_object.setSessionId("123456");
g_object.save("local", (result) => {
console.log("save callback");
console.info("save sessionId: " + result.sessionId); console.info("save sessionId: " + result.sessionId);
console.info("save version: " + result.version); console.info("save version: " + result.version);
console.info("save deviceId: " + result.deviceId); console.info("save deviceId: " + result.deviceId);
...@@ -637,37 +402,9 @@ The saved data will be released in the following cases: ...@@ -637,37 +402,9 @@ The saved data will be released in the following cases:
**Example** **Example**
```js ```js
import distributedObject from '@ohos.data.distributedDataObject';
import featureAbility from '@ohos.ability.featureAbility';
// Obtain the context.
let context = featureAbility.getContext();
let g_object = distributedObject.create(context,{name:"Amy", age:18, isVis:false});
g_object.setSessionId("123456"); g_object.setSessionId("123456");
g_object.save("local").then((result) => { g_object.save("local").then((result) => {
console.log("save callback"); console.info("save callback");
console.info("save sessionId " + result.sessionId);
console.info("save version " + result.version);
console.info("save deviceId " + result.deviceId);
}, () => {
console.error("save failed");
});
```
```js
import distributedObject from '@ohos.data.distributedDataObject';
import UIAbility from '@ohos.app.ability.UIAbility';
// Obtain the context.
let context;
class EntryAbility extends UIAbility {
onWindowStageCreate(windowStage){
context = this.context
}
}
let g_object = distributedObject.create(context,{name:"Amy", age:18, isVis:false});
g_object.setSessionId("123456");
g_object.save("local").then((result) => {
console.log("save callback");
console.info("save sessionId " + result.sessionId); console.info("save sessionId " + result.sessionId);
console.info("save version " + result.version); console.info("save version " + result.version);
console.info("save deviceId " + result.deviceId); console.info("save deviceId " + result.deviceId);
...@@ -680,7 +417,7 @@ g_object.save("local").then((result) => { ...@@ -680,7 +417,7 @@ g_object.save("local").then((result) => {
revokeSave(callback: AsyncCallback&lt;RevokeSaveSuccessResponse&gt;): void revokeSave(callback: AsyncCallback&lt;RevokeSaveSuccessResponse&gt;): void
Revokes the saving operation of a distributed data object. This API uses an asynchronous callback to return the result. Revokes the saving operation of this distributed data object. This API uses an asynchronous callback to return the result.
If the object is saved on the local device, the data saved on all trusted devices will be deleted. If the object is saved on the local device, the data saved on all trusted devices will be deleted.
If the object is stored on another device, the data on the local device will be deleted. If the object is stored on another device, the data on the local device will be deleted.
...@@ -695,55 +432,19 @@ If the object is stored on another device, the data on the local device will be ...@@ -695,55 +432,19 @@ If the object is stored on another device, the data on the local device will be
**Example** **Example**
FA model:
```js ```js
import distributedObject from '@ohos.data.distributedDataObject';
import featureAbility from '@ohos.ability.featureAbility';
// Obtain the context.
let context = featureAbility.getContext();
let g_object = distributedObject.create(context, {name:"Amy", age:18, isVis:false});
g_object.setSessionId("123456"); g_object.setSessionId("123456");
// Save data for persistence. // Save data for persistence.
g_object.save("local", (result) => { g_object.save("local", (result) => {
console.log("save callback"); console.info("save callback");
console.info("save sessionId " + result.sessionId);
console.info("save version " + result.version);
console.info("save deviceId " + result.deviceId);
});
// Delete the persistence data.
g_object.revokeSave((result) => {
console.log("revokeSave callback");
console.log("revokeSave sessionId " + result.sessionId);
});
```
Stage model:
```ts
import distributedObject from '@ohos.data.distributedDataObject';
import UIAbility from '@ohos.app.ability.UIAbility';
// Obtain the context.
let context;
class EntryAbility extends UIAbility {
onWindowStageCreate(windowStage) {
context = this.context
}
}
let g_object = distributedObject.create(context, {name:"Amy", age:18, isVis:false});
g_object.setSessionId("123456");
// Save data for persistence.
g_object.save("local", (result) => {
console.log("save callback");
console.info("save sessionId " + result.sessionId); console.info("save sessionId " + result.sessionId);
console.info("save version " + result.version); console.info("save version " + result.version);
console.info("save deviceId " + result.deviceId); console.info("save deviceId " + result.deviceId);
}); });
// Delete the persistence data. // Delete the persistence data.
g_object.revokeSave((result) => { g_object.revokeSave((result) => {
console.log("revokeSave callback"); console.info("revokeSave callback");
console.log("revokeSave sessionId " + result.sessionId); console.info("revokeSave sessionId " + result.sessionId);
}); });
``` ```
...@@ -751,7 +452,7 @@ g_object.revokeSave((result) => { ...@@ -751,7 +452,7 @@ g_object.revokeSave((result) => {
revokeSave(): Promise&lt;RevokeSaveSuccessResponse&gt; revokeSave(): Promise&lt;RevokeSaveSuccessResponse&gt;
Revokes the saving operation of a distributed data object. This API uses a promise to return the result. Revokes the saving operation of this distributed data object. This API uses a promise to return the result.
If the object is saved on the local device, the data saved on all trusted devices will be deleted. If the object is saved on the local device, the data saved on all trusted devices will be deleted.
If the object is stored on another device, the data on the local device will be deleted. If the object is stored on another device, the data on the local device will be deleted.
...@@ -766,18 +467,11 @@ If the object is stored on another device, the data on the local device will be ...@@ -766,18 +467,11 @@ If the object is stored on another device, the data on the local device will be
**Example** **Example**
FA model:
```ts ```ts
import distributedObject from '@ohos.data.distributedDataObject';
import featureAbility from '@ohos.ability.featureAbility';
// Obtain the context.
let context = featureAbility.getContext();
let g_object = distributedObject.create(context, {name:"Amy", age:18, isVis:false});
g_object.setSessionId("123456"); g_object.setSessionId("123456");
// Save data for persistence. // Save data for persistence.
g_object.save("local").then((result) => { g_object.save("local").then((result) => {
console.log("save callback"); console.info("save callback");
console.info("save sessionId " + result.sessionId); console.info("save sessionId " + result.sessionId);
console.info("save version " + result.version); console.info("save version " + result.version);
console.info("save deviceId " + result.deviceId); console.info("save deviceId " + result.deviceId);
...@@ -786,41 +480,8 @@ g_object.save("local").then((result) => { ...@@ -786,41 +480,8 @@ g_object.save("local").then((result) => {
}); });
// Delete the persistence data. // Delete the persistence data.
g_object.revokeSave().then((result) => { g_object.revokeSave().then((result) => {
console.log("revokeSave callback"); console.info("revokeSave callback");
console.log("sessionId" + result.sessionId); console.info("sessionId" + result.sessionId);
}, () => {
console.error("revokeSave failed");
});
```
Stage model:
```ts
import distributedObject from '@ohos.data.distributedDataObject';
import UIAbility from '@ohos.app.ability.UIAbility';
// Obtain the context.
let context;
class EntryAbility extends UIAbility {
onWindowStageCreate(windowStage) {
context = this.context
}
}
let g_object = distributedObject.create(context, {name:"Amy", age:18, isVis:false});
g_object.setSessionId("123456");
g_object.save("local").then((result) => {
console.log("save callback");
console.info("save sessionId " + result.sessionId);
console.info("save version " + result.version);
console.info("save deviceId " + result.deviceId);
}, () => {
console.error("save failed");
});
// Delete the persistence data.
g_object.revokeSave().then((result) => {
console.log("revokeSave callback");
console.log("sessionId" + result.sessionId);
}, () => { }, () => {
console.error("revokeSave failed"); console.error("revokeSave failed");
}); });
...@@ -861,7 +522,7 @@ let g_object = distributedObject.createDistributedObject({name:"Amy", age:18, is ...@@ -861,7 +522,7 @@ let g_object = distributedObject.createDistributedObject({name:"Amy", age:18, is
## DistributedObject<sup>(deprecated)</sup> ## DistributedObject<sup>(deprecated)</sup>
Provides APIs for managing a distributed data object. Provides APIs for managing a distributed data object. Before using any API of this class, use [createDistributedObject()](#distributedobjectcreatedistributedobjectdeprecated) to create a **DistributedObject** object.
### setSessionId<sup>(deprecated)</sup> ### setSessionId<sup>(deprecated)</sup>
...@@ -1004,7 +665,7 @@ Unsubscribes from the status change of this distributed data object. ...@@ -1004,7 +665,7 @@ Unsubscribes from the status change of this distributed data object.
> **NOTE** > **NOTE**
> >
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [off('status')](#offstatus9) instead. > This API is supported since API version 8 and deprecated since API version 9. You are advised to use [off('status')](#offstatus9).
**System capability**: SystemCapability.DistributedDataManager.DataObject.DistributedObject **System capability**: SystemCapability.DistributedDataManager.DataObject.DistributedObject
......
...@@ -38,7 +38,7 @@ Obtains a **Preferences** instance. This API uses an asynchronous callback to re ...@@ -38,7 +38,7 @@ Obtains a **Preferences** instance. This API uses an asynchronous callback to re
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------------------------------------------------ | ---- | ------------------------------------------------------------ | | -------- | ------------------------------------------------ | ---- | ------------------------------------------------------------ |
| context | Context | Yes | Application context.<br>For details about the application context of the FA model, see [Context](js-apis-inner-app-context.md).<br>For details about the application context of the stage model, see [Context](js-apis-ability-context.md). | | context | Context | Yes | Application context.<br>For details about the application context of the FA model, see [Context](js-apis-inner-app-context.md).<br>For details about the application context of the stage model, see [Context](js-apis-inner-application-uiAbilityContext.md). |
| name | string | Yes | Name of the **Preferences** instance.| | name | string | Yes | Name of the **Preferences** instance.|
| callback | AsyncCallback&lt;[Preferences](#preferences)&gt; | Yes | Callback invoked to return the result. If the operation is successful, **err** is **undefined** and **object** is the **Preferences** instance obtained. Otherwise, **err** is an error code.| | callback | AsyncCallback&lt;[Preferences](#preferences)&gt; | Yes | Callback invoked to return the result. If the operation is successful, **err** is **undefined** and **object** is the **Preferences** instance obtained. Otherwise, **err** is an error code.|
...@@ -55,42 +55,40 @@ let preferences = null; ...@@ -55,42 +55,40 @@ let preferences = null;
try { try {
data_preferences.getPreferences(context, 'mystore', function (err, val) { data_preferences.getPreferences(context, 'mystore', function (err, val) {
if (err) { if (err) {
console.info("Failed to get the preferences. code =" + err.code + ", message =" + err.message); console.info("Failed to obtain the preferences. code =" + err.code + ", message =" + err.message);
return; return;
} }
console.info("Got the preferences successfully."); preferences = val;
console.info("Obtained the preferences successfully.");
}) })
} catch (err) { } catch (err) {
console.info("Failed to get the preferences. code =" + err.code + ", message =" + err.message); console.info("Failed to obtain the preferences. code =" + err.code + ", message =" + err.message);
} }
``` ```
Stage model: Stage model:
```ts ```ts
// Obtain the context.
import UIAbility from '@ohos.app.ability.UIAbility'; import UIAbility from '@ohos.app.ability.UIAbility';
let context = null; let preferences = null;
class EntryAbility extends UIAbility { class EntryAbility extends UIAbility {
onWindowStageCreate(windowStage){ onWindowStageCreate(windowStage) {
context = this.context; try {
data_preferences.getPreferences(this.context, 'mystore', function (err, val) {
if (err) {
console.info("Failed to obtain the preferences. code =" + err.code + ", message =" + err.message);
return;
}
preferences = val;
console.info("Obtained the preferences successfully.");
})
} catch (err) {
console.info("Failed to obtain the preferences. code =" + err.code + ", message =" + err.message);
}
} }
} }
let preferences = null;
try {
data_preferences.getPreferences(context, 'mystore', function (err, val) {
if (err) {
console.info("Failed to get the preferences. code =" + err.code + ", message =" + err.message);
return;
}
console.info("Got the preferences successfully.");
})
} catch (err) {
console.info("Failed to get the preferences. code =" + err.code + ", message =" + err.message);
}
``` ```
## data_preferences.getPreferences ## data_preferences.getPreferences
...@@ -105,7 +103,7 @@ Obtains a **Preferences** instance. This API uses a promise to return the result ...@@ -105,7 +103,7 @@ Obtains a **Preferences** instance. This API uses a promise to return the result
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| ------- | ------------------------------------- | ---- | ----------------------- | | ------- | ------------------------------------- | ---- | ----------------------- |
| context | Context | Yes | Application context.<br>For details about the application context of the FA model, see [Context](js-apis-inner-app-context.md).<br>For details about the application context of the stage model, see [Context](js-apis-ability-context.md). | | context | Context | Yes | Application context.<br>For details about the application context of the FA model, see [Context](js-apis-inner-app-context.md).<br>For details about the application context of the stage model, see [Context](js-apis-inner-application-uiAbilityContext.md). |
| name | string | Yes | Name of the **Preferences** instance.| | name | string | Yes | Name of the **Preferences** instance.|
**Return value** **Return value**
...@@ -128,41 +126,37 @@ try { ...@@ -128,41 +126,37 @@ try {
let promise = data_preferences.getPreferences(context, 'mystore'); let promise = data_preferences.getPreferences(context, 'mystore');
promise.then((object) => { promise.then((object) => {
preferences = object; preferences = object;
console.info("Got the preferences successfully."); console.info("Obtained the preferences successfully.");
}).catch((err) => { }).catch((err) => {
console.log("Failed to get the preferences. code =" + err.code + ", message =" + err.message); console.info("Failed to obtain the preferences. code =" + err.code + ", message =" + err.message);
}) })
} catch(err) { } catch(err) {
console.log("Failed to get the preferences. code =" + err.code + ", message =" + err.message); console.info("Failed to obtain the preferences. code =" + err.code + ", message =" + err.message);
} }
``` ```
Stage model: Stage model:
```ts ```ts
// Obtain the context.
import UIAbility from '@ohos.app.ability.UIAbility'; import UIAbility from '@ohos.app.ability.UIAbility';
let context = null; let preferences = null;
class EntryAbility extends UIAbility { class EntryAbility extends UIAbility {
onWindowStageCreate(windowStage){ onWindowStageCreate(windowStage) {
context = this.context; try {
let promise = data_preferences.getPreferences(this.context, 'mystore');
promise.then((object) => {
preferences = object;
console.info("Obtained the preferences successfully.");
}).catch((err) => {
console.info("Failed to obtain the preferences. code =" + err.code + ", message =" + err.message);
})
} catch(err) {
console.info("Failed to obtain the preferences. code =" + err.code + ", message =" + err.message);
}
} }
} }
let preferences = null;
try {
let promise = data_preferences.getPreferences(context, 'mystore');
promise.then((object) => {
preferences = object;
console.info("Got the preferences successfully.");
}).catch((err) => {
console.log("Failed to get the preferences. code =" + err.code + ", message =" + err.message);
})
} catch(err) {
console.log("Failed to get the preferences. code =" + err.code + ", message =" + err.message);
}
``` ```
## data_preferences.deletePreferences ## data_preferences.deletePreferences
...@@ -181,7 +175,7 @@ The deleted **Preferences** instance cannot be used for data operations. Otherwi ...@@ -181,7 +175,7 @@ The deleted **Preferences** instance cannot be used for data operations. Otherwi
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------------------------------------- | ---- | ---------------------------------------------------- | | -------- | ------------------------------------- | ---- | ---------------------------------------------------- |
| context | Context | Yes | Application context.<br>For details about the application context of the FA model, see [Context](js-apis-inner-app-context.md).<br>For details about the application context of the stage model, see [Context](js-apis-ability-context.md). | | context | Context | Yes | Application context.<br>For details about the application context of the FA model, see [Context](js-apis-inner-app-context.md).<br>For details about the application context of the stage model, see [Context](js-apis-inner-application-uiAbilityContext.md). |
| name | string | Yes | Name of the **Preferences** instance to delete. | | name | string | Yes | Name of the **Preferences** instance to delete. |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error code.| | callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error code.|
...@@ -218,27 +212,22 @@ try { ...@@ -218,27 +212,22 @@ try {
Stage model: Stage model:
```ts ```ts
// Obtain the context.
import UIAbility from '@ohos.app.ability.UIAbility'; import UIAbility from '@ohos.app.ability.UIAbility';
let context = null;
class EntryAbility extends UIAbility { class EntryAbility extends UIAbility {
onWindowStageCreate(windowStage){ onWindowStageCreate(windowStage) {
context = this.context; try {
} data_preferences.deletePreferences(this.context, 'mystore', function (err, val) {
} if (err) {
console.info("Failed to delete the preferences. code =" + err.code + ", message =" + err.message);
try { return;
data_preferences.deletePreferences(context, 'mystore', function (err, val) { }
if (err) { console.info("Deleted the preferences successfully." );
})
} catch (err) {
console.info("Failed to delete the preferences. code =" + err.code + ", message =" + err.message); console.info("Failed to delete the preferences. code =" + err.code + ", message =" + err.message);
return;
} }
console.info("Deleted the preferences successfully." ); }
})
} catch (err) {
console.info("Failed to delete the preferences. code =" + err.code + ", message =" + err.message);
} }
``` ```
...@@ -258,7 +247,7 @@ The deleted **Preferences** instance cannot be used for data operations. Otherwi ...@@ -258,7 +247,7 @@ The deleted **Preferences** instance cannot be used for data operations. Otherwi
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| ------- | ------------------------------------- | ---- | ----------------------- | | ------- | ------------------------------------- | ---- | ----------------------- |
| context | Context | Yes | Application context.<br>For details about the application context of the FA model, see [Context](js-apis-inner-app-context.md).<br>For details about the application context of the stage model, see [Context](js-apis-ability-context.md). | | context | Context | Yes | Application context.<br>For details about the application context of the FA model, see [Context](js-apis-inner-app-context.md).<br>For details about the application context of the stage model, see [Context](js-apis-inner-application-uiAbilityContext.md). |
| name | string | Yes | Name of the **Preferences** instance to delete.| | name | string | Yes | Name of the **Preferences** instance to delete.|
**Return value** **Return value**
...@@ -299,27 +288,22 @@ try { ...@@ -299,27 +288,22 @@ try {
Stage model: Stage model:
```ts ```ts
// Obtain the context.
import UIAbility from '@ohos.app.ability.UIAbility'; import UIAbility from '@ohos.app.ability.UIAbility';
let context = null;
class EntryAbility extends UIAbility { class EntryAbility extends UIAbility {
onWindowStageCreate(windowStage){ onWindowStageCreate(windowStage) {
context = this.context; try{
let promise = data_preferences.deletePreferences(this.context, 'mystore');
promise.then(() => {
console.info("Deleted the preferences successfully.");
}).catch((err) => {
console.info("Failed to delete the preferences. code =" + err.code + ", message =" + err.message);
})
} catch(err) {
console.info("Failed to delete the preferences. code =" + err.code + ", message =" + err.message);
}
} }
} }
try{
let promise = data_preferences.deletePreferences(context, 'mystore');
promise.then(() => {
console.info("Deleted the preferences successfully.");
}).catch((err) => {
console.info("Failed to delete the preferences. code =" + err.code + ", message =" + err.message);
})
} catch(err) {
console.info("Failed to delete the preferences. code =" + err.code + ", message =" + err.message);
}
``` ```
## data_preferences.removePreferencesFromCache ## data_preferences.removePreferencesFromCache
...@@ -336,7 +320,7 @@ The removed **Preferences** instance cannot be used for data operations. Otherwi ...@@ -336,7 +320,7 @@ The removed **Preferences** instance cannot be used for data operations. Otherwi
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------------------------------------- | ---- | ---------------------------------------------------- | | -------- | ------------------------------------- | ---- | ---------------------------------------------------- |
| context | Context | Yes | Application context.<br>For details about the application context of the FA model, see [Context](js-apis-inner-app-context.md).<br>For details about the application context of the stage model, see [Context](js-apis-ability-context.md). | | context | Context | Yes | Application context.<br>For details about the application context of the FA model, see [Context](js-apis-inner-app-context.md).<br>For details about the application context of the stage model, see [Context](js-apis-inner-application-uiAbilityContext.md). |
| name | string | Yes | Name of the **Preferences** instance to remove. | | name | string | Yes | Name of the **Preferences** instance to remove. |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error code.| | callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error code.|
...@@ -365,27 +349,22 @@ try { ...@@ -365,27 +349,22 @@ try {
Stage model: Stage model:
```ts ```ts
// Obtain the context.
import UIAbility from '@ohos.app.ability.UIAbility'; import UIAbility from '@ohos.app.ability.UIAbility';
let context = null;
class EntryAbility extends UIAbility { class EntryAbility extends UIAbility {
onWindowStageCreate(windowStage){ onWindowStageCreate(windowStage) {
context = this.context; try {
} data_preferences.removePreferencesFromCache(this.context, 'mystore', function (err, val) {
} if (err) {
console.info("Failed to remove the preferences. code =" + err.code + ", message =" + err.message);
try { return;
data_preferences.removePreferencesFromCache(context, 'mystore', function (err, val) { }
if (err) { console.info("Removed the preferences successfully.");
})
} catch (err) {
console.info("Failed to remove the preferences. code =" + err.code + ", message =" + err.message); console.info("Failed to remove the preferences. code =" + err.code + ", message =" + err.message);
return;
} }
console.info("Removed the preferences successfully."); }
})
} catch (err) {
console.info("Failed to remove the preferences. code =" + err.code + ", message =" + err.message);
} }
``` ```
...@@ -404,7 +383,7 @@ The removed **Preferences** instance cannot be used for data operations. Otherwi ...@@ -404,7 +383,7 @@ The removed **Preferences** instance cannot be used for data operations. Otherwi
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| ------- | ------------------------------------- | ---- | ----------------------- | | ------- | ------------------------------------- | ---- | ----------------------- |
| context | Context | Yes | Application context.<br>For details about the application context of the FA model, see [Context](js-apis-inner-app-context.md).<br>For details about the application context of the stage model, see [Context](js-apis-ability-context.md). | | context | Context | Yes | Application context.<br>For details about the application context of the FA model, see [Context](js-apis-inner-app-context.md).<br>For details about the application context of the stage model, see [Context](js-apis-inner-application-uiAbilityContext.md). |
| name | string | Yes | Name of the **Preferences** instance to remove.| | name | string | Yes | Name of the **Preferences** instance to remove.|
**Return value** **Return value**
...@@ -437,25 +416,22 @@ try { ...@@ -437,25 +416,22 @@ try {
Stage model: Stage model:
```ts ```ts
// Obtain the context.
import UIAbility from '@ohos.app.ability.UIAbility'; import UIAbility from '@ohos.app.ability.UIAbility';
let context = null;
class EntryAbility extends UIAbility { class EntryAbility extends UIAbility {
onWindowStageCreate(windowStage){ onWindowStageCreate(windowStage) {
context = this.context; try {
let promise = data_preferences.removePreferencesFromCache(this.context, 'mystore');
promise.then(() => {
console.info("Removed the preferences successfully.");
}).catch((err) => {
console.info("Failed to remove the preferences. code =" + err.code + ", message =" + err.message);
})
} catch(err) {
console.info("Failed to remove the preferences. code =" + err.code + ", message =" + err.message);
}
} }
} }
try {
let promise = data_preferences.removePreferencesFromCache(context, 'mystore');
promise.then(() => {
console.info("Removed the preferences successfully.");
}).catch((err) => {
console.info("Failed to remove the preferences. code =" + err.code + ", message =" + err.message);
})
} catch(err) {
console.info("Failed to remove the preferences. code =" + err.code + ", message =" + err.message);
}
``` ```
## Preferences ## Preferences
...@@ -469,7 +445,7 @@ Before calling any method of **Preferences**, you must obtain a **Preferences** ...@@ -469,7 +445,7 @@ Before calling any method of **Preferences**, you must obtain a **Preferences**
get(key: string, defValue: ValueType, callback: AsyncCallback&lt;ValueType&gt;): void get(key: string, defValue: ValueType, callback: AsyncCallback&lt;ValueType&gt;): void
Obtains the value of a key. This API uses an asynchronous callback to return the result. If the value is **null** or is not the type of the default value, the default value is returned. Obtains the value of a key. This API uses an asynchronous callback to return the result. If the value is **null** or is not of the default value type, **defValue** is returned.
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core **System capability**: SystemCapability.DistributedDataManager.Preferences.Core
...@@ -487,13 +463,13 @@ Obtains the value of a key. This API uses an asynchronous callback to return the ...@@ -487,13 +463,13 @@ Obtains the value of a key. This API uses an asynchronous callback to return the
try { try {
preferences.get('startup', 'default', function (err, val) { preferences.get('startup', 'default', function (err, val) {
if (err) { if (err) {
console.info("Failed to get the value of 'startup'. code =" + err.code + ", message =" + err.message); console.info("Failed to obtain the value of 'startup'. code =" + err.code + ", message =" + err.message);
return; return;
} }
console.info("Obtained the value of 'startup' successfully. val: " + val); console.info("Obtained the value of 'startup' successfully. val: " + val);
}) })
} catch (err) { } catch (err) {
console.info("Failed to get the value of 'startup'. code =" + err.code + ", message =" + err.message); console.info("Failed to obtain the value of 'startup'. code =" + err.code + ", message =" + err.message);
} }
``` ```
...@@ -502,7 +478,7 @@ try { ...@@ -502,7 +478,7 @@ try {
get(key: string, defValue: ValueType): Promise&lt;ValueType&gt; get(key: string, defValue: ValueType): Promise&lt;ValueType&gt;
Obtains the value of a key. This API uses a promise to return the result. If the value is **null** or is not the type of the default value, the default value is returned. Obtains the value of a key. This API uses a promise to return the result. If the value is **null** or is not of the default value type, **defValue** is returned.
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core **System capability**: SystemCapability.DistributedDataManager.Preferences.Core
...@@ -530,7 +506,7 @@ try { ...@@ -530,7 +506,7 @@ try {
console.info("Failed to get value of 'startup'. code =" + err.code + ", message =" + err.message); console.info("Failed to get value of 'startup'. code =" + err.code + ", message =" + err.message);
}) })
} catch(err) { } catch(err) {
console.info("Failed to get the value of 'startup'. code =" + err.code + ", message =" + err.message); console.info("Failed to obtain the value of 'startup'. code =" + err.code + ", message =" + err.message);
} }
``` ```
...@@ -672,7 +648,7 @@ try { ...@@ -672,7 +648,7 @@ try {
has(key: string, callback: AsyncCallback&lt;boolean&gt;): void has(key: string, callback: AsyncCallback&lt;boolean&gt;): void
Checks whether this **Preferences** instance contains a KV pair with the given key. This API uses an asynchronous callback to return the result.. Checks whether this **Preferences** instance contains a KV pair with the given key. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core **System capability**: SystemCapability.DistributedDataManager.Preferences.Core
...@@ -708,7 +684,7 @@ try { ...@@ -708,7 +684,7 @@ try {
has(key: string): Promise&lt;boolean&gt; has(key: string): Promise&lt;boolean&gt;
Checks whether this **Preferences** instance contains a KV pair with the given key. This API uses a promise to return the result.. Checks whether this **Preferences** instance contains a KV pair with the given key. This API uses a promise to return the result.
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core **System capability**: SystemCapability.DistributedDataManager.Preferences.Core
...@@ -804,10 +780,10 @@ try { ...@@ -804,10 +780,10 @@ try {
promise.then(() => { promise.then(() => {
console.info("Deleted the key 'startup'."); console.info("Deleted the key 'startup'.");
}).catch((err) => { }).catch((err) => {
console.log("Failed to delete the key 'startup'. code =" + err.code +", message =" + err.message); console.info("Failed to delete the key 'startup'. code =" + err.code +", message =" + err.message);
}) })
} catch(err) { } catch(err) {
console.log("Failed to delete the key 'startup'. code =" + err.code +", message =" + err.message); console.info("Failed to delete the key 'startup'. code =" + err.code +", message =" + err.message);
} }
``` ```
...@@ -955,7 +931,7 @@ Subscribes to data changes. A callback will be triggered to return the new value ...@@ -955,7 +931,7 @@ Subscribes to data changes. A callback will be triggered to return the new value
try { try {
data_preferences.getPreferences(this.context, 'mystore', function (err, preferences) { data_preferences.getPreferences(this.context, 'mystore', function (err, preferences) {
if (err) { if (err) {
console.info("Failed to get the preferences."); console.info("Failed to obtain the preferences.");
return; return;
} }
let observer = function (key) { let observer = function (key) {
...@@ -1005,7 +981,7 @@ Unsubscribes from data changes. ...@@ -1005,7 +981,7 @@ Unsubscribes from data changes.
try { try {
data_preferences.getPreferences(this.context, 'mystore', function (err, preferences) { data_preferences.getPreferences(this.context, 'mystore', function (err, preferences) {
if (err) { if (err) {
console.info("Failed to get the preferences."); console.info("Failed to obtain the preferences.");
return; return;
} }
let observer = function (key) { let observer = function (key) {
......
...@@ -367,7 +367,7 @@ Provides APIs for obtaining and modifying storage data. ...@@ -367,7 +367,7 @@ Provides APIs for obtaining and modifying storage data.
getSync(key: string, defValue: ValueType): ValueType getSync(key: string, defValue: ValueType): ValueType
Obtains the value corresponding to a key. If the value is null or not in the default value format, the default value is returned. Obtains the value corresponding to a key. If the value is null or not of the default value type, **defValue** is returned.
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core **System capability**: SystemCapability.DistributedDataManager.Preferences.Core
...@@ -396,7 +396,7 @@ console.info("The value of startup is " + value); ...@@ -396,7 +396,7 @@ console.info("The value of startup is " + value);
get(key: string, defValue: ValueType, callback: AsyncCallback&lt;ValueType&gt;): void get(key: string, defValue: ValueType, callback: AsyncCallback&lt;ValueType&gt;): void
Obtains the value corresponding to a key. If the value is null or not in the default value format, the default value is returned. This API uses an asynchronous callback to return the result. Obtains the value corresponding to a key. If the value is null or not of the default value type, **defValue** is returned. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core **System capability**: SystemCapability.DistributedDataManager.Preferences.Core
...@@ -425,7 +425,7 @@ storage.get('startup', 'default', function(err, value) { ...@@ -425,7 +425,7 @@ storage.get('startup', 'default', function(err, value) {
get(key: string, defValue: ValueType): Promise&lt;ValueType&gt; get(key: string, defValue: ValueType): Promise&lt;ValueType&gt;
Obtains the value corresponding to a key. If the value is null or not in the default value format, the default value is returned. This API uses a promise to return the result. Obtains the value corresponding to a key. If the value is null or not of the default value type, **defValue** is returned. This API uses a promise to return the result.
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core **System capability**: SystemCapability.DistributedDataManager.Preferences.Core
......
...@@ -211,7 +211,6 @@ Obtains information about the device root nodes of the file management service t ...@@ -211,7 +211,6 @@ Obtains information about the device root nodes of the file management service t
getRoots(callback:AsyncCallback&lt;RootIterator&gt;) : void; getRoots(callback:AsyncCallback&lt;RootIterator&gt;) : void;
Obtains information about the device root nodes of the file management service type connected to the **Helper** object. This API uses an asynchronous callback to return the result. Obtains information about the device root nodes of the file management service type connected to the **Helper** object. This API uses an asynchronous callback to return the result.
The callback has a **RootIterator** object, which returns [RootInfo](#rootinfo) through [next()](#rootiteratornext). The callback has a **RootIterator** object, which returns [RootInfo](#rootinfo) through [next()](#rootiteratornext).
**System capability**: SystemCapability.FileManagement.UserFileService **System capability**: SystemCapability.FileManagement.UserFileService
...@@ -255,7 +254,7 @@ The callback has a **RootIterator** object, which returns [RootInfo](#rootinfo) ...@@ -255,7 +254,7 @@ The callback has a **RootIterator** object, which returns [RootInfo](#rootinfo)
listFile(filter?: Filter) : FileIterator listFile(filter?: Filter) : FileIterator
Synchronously obtains the **FileIterator** object of the first-level files (file directory) matching the conditions of the filter from the device root node. The **FileIterator** object then returns [FileInfo](#fileinfo) by using [next()](#fileiteratornext). Synchronously obtains the **FileIterator** object of the first-level files (directory) matching the conditions of the filter from the device root node. The **FileIterator** object then returns [FileInfo](#fileinfo) by using [next()](#fileiteratornext).
**System capability**: SystemCapability.FileManagement.UserFileService **System capability**: SystemCapability.FileManagement.UserFileService
...@@ -356,7 +355,7 @@ Recursively obtains the **FileIterator** object of the files matching the condit ...@@ -356,7 +355,7 @@ Recursively obtains the **FileIterator** object of the files matching the condit
listFile(filter?: Filter) : FileIterator listFile(filter?: Filter) : FileIterator
Synchronously obtains the **FileIterator** object of the next-level files (file directories) matching the conditions of the filter from a directory. The **FileIterator** object then returns [FileInfo](#fileinfo) by using [next()](#fileiteratornext). Synchronously obtains the **FileIterator** object of the next-level files (directories) matching the conditions of the filter from a directory. The **FileIterator** object then returns [FileInfo](#fileinfo) by using [next()](#fileiteratornext).
**System capability**: SystemCapability.FileManagement.UserFileService **System capability**: SystemCapability.FileManagement.UserFileService
......
...@@ -14,7 +14,7 @@ The **PermissionRequestResult** module defines the result of a permission reques ...@@ -14,7 +14,7 @@ The **PermissionRequestResult** module defines the result of a permission reques
| Name| Type| Readable| Writable| Description| | Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- | -------- |
| permissions | Array&lt;string&gt; | Yes| No| Permissions requested.| | permissions | Array&lt;string&gt; | Yes| No| Permissions requested.|
| authResults | Array&lt;number&gt; | Yes| No|Resule of the permission Request.<br>**-1**: The permission has been set and no dialog box will be displayed. Users can modify the permission in **Settings**.<br>**0**: No operation is required.<br>**1**: Dynamic user authorization is required via a dialog window .<br>**2**: The request is invalid. Possible causes are as follows:<br>- The permission is not declared in the configuration file.<br>- The permission name is invalid.<br>- Special conditions for applying for the permission do not satisfied. See [ohos.permission.LOCATION](../../security/permission-list.md#ohospermissionlocation) and [ohos.permission.APPROXIMATELY_LOCATION](../../security/permission-list.md#ohospermissionapproximately_location).| | authResults | Array&lt;number&gt; | Yes| No|Result of the permission Request.<br>**-1**: The permission has been set and no dialog box will be displayed. Users can modify the permission in **Settings**.<br>**0**: No operation is required.<br>**1**: Dynamic user authorization is required via a dialog window .<br>**2**: The request is invalid. Possible causes are as follows:<br>- The permission is not declared in the configuration file.<br>- The permission name is invalid.<br>- Special conditions for applying for the permission do not satisfied. See [ohos.permission.LOCATION](../../security/permission-list.md#ohospermissionlocation) and [ohos.permission.APPROXIMATELY_LOCATION](../../security/permission-list.md#ohospermissionapproximately_location).|
## Usage ## Usage
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册