1# @ohos.data.distributedDataObject (Distributed Data Object) 2 3The **distributedDataObject** module provides basic data object management, including creating, querying, deleting, modifying, and subscribing to data objects, and distributed data object collaboration for the same application among multiple devices. 4 5> **NOTE** 6> 7> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version. 8 9 10## Modules to Import 11 12```js 13import distributedObject from '@ohos.data.distributedDataObject'; 14``` 15 16## distributedObject.create<sup>9+</sup> 17 18create(context: Context, source: object): DataObject 19 20Creates a distributed data object. 21 22**System capability**: SystemCapability.DistributedDataManager.DataObject.DistributedObject 23 24**Parameters** 25 26| Name| Type| Mandatory| Description| 27| -------- | -------- | -------- | -------- | 28| 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).| 29| source | object | Yes| Attributes of the distributed data object.| 30 31**Return value** 32 33| Type| Description| 34| -------- | -------- | 35| [DataObject](#dataobject) | Distributed data object created.| 36 37**Example** 38 39FA model: 40 41```js 42// Import the module. 43import distributedObject from '@ohos.data.distributedDataObject'; 44import featureAbility from '@ohos.ability.featureAbility'; 45// Obtain the context. 46let context = featureAbility.getContext(); 47// Create a distributed data object, which contains attributes of the string, number, boolean, and object types. 48let g_object = distributedObject.create(context, {name:"Amy", age:18, isVis:false, parent:{mother:"jack mom",father:"jack Dad"}}); 49``` 50 51Stage model: 52 53```ts 54// Import the module. 55import distributedObject from '@ohos.data.distributedDataObject'; 56import UIAbility from '@ohos.app.ability.UIAbility'; 57 58let g_object = null; 59 60class EntryAbility extends UIAbility { 61 onWindowStageCreate(windowStage){ 62 // Create a distributed data object, which has attributes of the string, number, boolean, and object types. 63 g_object = distributedObject.create(this.context, {name:"Amy", age:18, isVis:false, parent:{mother:"jack mom",father:"jack Dad"}}); 64 } 65} 66``` 67 68## distributedObject.genSessionId 69 70genSessionId(): string 71 72Creates a random session ID. 73 74**System capability**: SystemCapability.DistributedDataManager.DataObject.DistributedObject 75 76**Return value** 77 78| Type| Description| 79| -------- | -------- | 80| string | Session ID created.| 81 82**Example** 83 84```js 85import distributedObject from '@ohos.data.distributedDataObject'; 86let sessionId = distributedObject.genSessionId(); 87``` 88 89## SaveSuccessResponse<sup>9+</sup> 90 91Called when the **Save()** API is successfully called. 92 93**System capability**: SystemCapability.DistributedDataManager.DataObject.DistributedObject 94 95| Name| Type| Mandatory| Description| 96| -------- | -------- | -------- | -------- | 97| sessionId | string | Yes| Unique ID for multi-device collaboration.| 98| version | number | Yes| Version of the distributed data object saved.| 99| deviceId | string | Yes| ID of the device where the distributed data object is stored. The default value is **local**, which identifies a local device. You can set it as required.| 100 101## RevokeSaveSuccessResponse<sup>9+</sup> 102 103Called when the **revokeSave()** API is successfully called. 104 105**System capability**: SystemCapability.DistributedDataManager.DataObject.DistributedObject 106 107| Name| Type| Mandatory| Description| 108| -------- | -------- | -------- | -------- | 109| sessionId | string | Yes| Unique ID for multi-device collaboration.| 110 111## DataObject 112 113Provides APIs for managing a distributed data object. Before using any API of this class, use [create()](#distributedobjectcreate9) to create a **DataObject** object. 114 115### setSessionId<sup>9+</sup> 116 117setSessionId(sessionId: string, callback: AsyncCallback<void>): void 118 119Sets a session ID for synchronization. Automatic synchronization is performed for multiple devices with the same session ID on a trusted network. 120 121**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC 122 123**System capability**: SystemCapability.DistributedDataManager.DataObject.DistributedObject 124 125**Parameters** 126 127| Name| Type| Mandatory| Description| 128| -------- | -------- | -------- | -------- | 129| sessionId | string | Yes| ID of a distributed data object on a trusted network.| 130| callback | AsyncCallback<void> | Yes| Asynchronous callback invoked when the session ID is successfully set.| 131 132**Error codes** 133 134 For details about the error codes, see [Distributed Data Object Error Codes](../errorcodes/errorcode-distributed-dataObject.md). 135 136| ID| Error Message| 137| -------- | -------- | 138| 15400001 | Failed to create the in-memory database.| 139 140**Example** 141 142```js 143// Add g_object to the distributed network. 144g_object.setSessionId(distributedObject.genSessionId(), ()=>{ 145 console.info("join session"); 146}); 147``` 148 149### setSessionId<sup>9+</sup> 150 151setSessionId(callback: AsyncCallback<void>): void 152 153Exits all joined sessions. 154 155**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC 156 157**System capability**: SystemCapability.DistributedDataManager.DataObject.DistributedObject 158 159**Parameters** 160 161| Name| Type| Mandatory| Description| 162| -------- | -------- | -------- | -------- | 163| callback | AsyncCallback<void> | Yes| Asynchronous callback invoked when the distributed data object exits all joined sessions.| 164 165**Error codes** 166 167 For details about the error codes, see [Distributed Data Object Error Codes](../errorcodes/errorcode-distributed-dataObject.md). 168 169| ID| Error Message| 170| -------- | -------- | 171| 15400001 | Failed to create the in-memory database.| 172 173**Example** 174 175```js 176// Add g_object to the distributed network. 177g_object.setSessionId(distributedObject.genSessionId(), ()=>{ 178 console.info("join session"); 179}); 180// Exit the distributed network. 181g_object.setSessionId(() => { 182 console.info("leave all lession."); 183}); 184``` 185 186### setSessionId<sup>9+</sup> 187 188setSessionId(sessionId?: string): Promise<void> 189 190Sets a session ID for synchronization. Automatic synchronization is performed for multiple devices with the same session ID on a trusted network. 191 192**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC 193 194**System capability**: SystemCapability.DistributedDataManager.DataObject.DistributedObject 195 196**Parameters** 197 198| Name| Type| Mandatory| Description| 199| -------- | -------- | -------- | -------- | 200| sessionId | string | No| ID of a distributed data object on a trusted network. To remove a distributed data object from the network, set this parameter to "" or leave it empty.| 201 202**Return value** 203 204| Type| Description| 205| -------- | -------- | 206| Promise<void> | Promise that returns no value.| 207 208**Error codes** 209 210 For details about the error codes, see [Distributed Data Object Error Codes](../errorcodes/errorcode-distributed-dataObject.md). 211 212| ID| Error Message| 213| -------- | -------- | 214| 15400001 | Failed to create the in-memory database.| 215 216**Example** 217 218```js 219// Add g_object to the distributed network. 220g_object.setSessionId(distributedObject.genSessionId()).then (()=>{ 221 console.info("join session."); 222 }).catch((error)=>{ 223 console.info("error:" + error.code + error.message); 224}); 225// Exit the distributed network. 226g_object.setSessionId().then (()=>{ 227 console.info("leave all lession."); 228 }).catch((error)=>{ 229 console.info("error:" + error.code + error.message); 230}); 231``` 232 233### on('change')<sup>9+</sup> 234 235on(type: 'change', callback: Callback<{ sessionId: string, fields: Array<string> }>): void 236 237Subscribes to data changes of this distributed data object. 238 239**System capability**: SystemCapability.DistributedDataManager.DataObject.DistributedObject 240 241**Parameters** 242 243| Name| Type| Mandatory| Description| 244| -------- | -------- | -------- | -------- | 245| type | string | Yes| Event type to subscribe to. The value is **change**, which indicates data changes.| 246| callback | Callback<{ sessionId: string, fields: Array<string> }> | Yes| Callback invoked to return the changes of the distributed data object.<br>**sessionId** indicates the session ID of the distributed data object.<br>**fields** indicates the changed attributes of the distributed data object.| 247 248**Example** 249 250```js 251globalThis.changeCallback = (sessionId, changeData) => { 252 console.info("change" + sessionId); 253 if (changeData != null && changeData != undefined) { 254 changeData.forEach(element => { 255 console.info("changed !" + element + " " + g_object[element]); 256 }); 257 } 258} 259g_object.on("change", globalThis.changeCallback); 260``` 261 262### off('change')<sup>9+</sup> 263 264off(type: 'change', callback?: Callback<{ sessionId: string, fields: Array<string> }>): void 265 266Unsubscribes from the data changes of this distributed data object. 267 268**System capability**: SystemCapability.DistributedDataManager.DataObject.DistributedObject 269 270**Parameters** 271 272| Name| Type| Mandatory| Description| 273| -------- | -------- | -------- | -------- | 274| type | string | Yes| Event type to unsubscribe from. The value is **change**, which indicates data changes.| 275| callback | Callback<{ sessionId: string, fields: Array<string> }> | 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.| 276 277 278**Example** 279 280```js 281// Unregister the specified data change callback. 282g_object.off("change", globalThis.changeCallback); 283// Unregister all data change callbacks. 284g_object.off("change"); 285``` 286 287### on('status')<sup>9+</sup> 288 289on(type: 'status', callback: Callback<{ sessionId: string, networkId: string, status: 'online' | 'offline' }>): void 290 291Subscribes to status changes of this distributed data object. 292 293**System capability**: SystemCapability.DistributedDataManager.DataObject.DistributedObject 294 295**Parameters** 296 297| Name| Type| Mandatory| Description| 298| -------- | -------- | -------- | -------- | 299| type | string | Yes| Event type to subscribe to. The value is **status**, which indicates the status change (online or offline) of the distributed data object.| 300| callback | Callback<{ sessionId: string, networkId: string, status: 'online' \| 'offline' }> | Yes| Callback invoked to return the status change.<br>**sessionId** indicates the session ID of the distributed data object.<br>**networkId** indicates the object device ID, that is, **deviceId**.<br>**status** indicates the object status, which can be online or offline.| 301 302**Example** 303 304```js 305globalThis.statusCallback = (sessionId, networkId, status) => { 306 globalThis.response += "status changed " + sessionId + " " + status + " " + networkId; 307} 308g_object.on("status", globalThis.statusCallback); 309``` 310 311### off('status')<sup>9+</sup> 312 313off(type: 'status', callback?: Callback<{ sessionId: string, deviceId: string, status: 'online' | 'offline' }>): void 314 315Unsubscribes from the status change of this distributed data object. 316 317**System capability**: SystemCapability.DistributedDataManager.DataObject.DistributedObject 318 319**Parameters** 320 321| Name| Type| Mandatory| Description| 322| -------- | -------- | -------- | -------- | 323| type | string | Yes| Event type to unsubscribe from. The value is **status**, which indicates the status change (online or offline) of the distributed data object.| 324| callback | Callback<{ sessionId: string, deviceId: string, status: 'online' \| 'offline' }> | No| Callback for status changes. If this parameter is not specified, all status change callbacks of this distributed data object will be unsubscribed from.<br>**sessionId** indicates the session ID of the distributed data object.<br>**deviceId** indicates the device ID of the distributed data object.<br>**status** indicates the object status, which can be online or offline.| 325 326 327**Example** 328 329```js 330globalThis.statusCallback = (sessionId, networkId, status) => { 331 globalThis.response += "status changed " + sessionId + " " + status + " " + networkId; 332} 333// Unregister the specified status change callback. 334g_object.off("status",globalThis.statusCallback); 335// Unregister all status change callbacks. 336g_object.off("status"); 337``` 338 339### save<sup>9+</sup> 340 341save(deviceId: string, callback: AsyncCallback<SaveSuccessResponse>): void 342 343Saves a distributed data object. This API uses an asynchronous callback to return the result. 344 345If the application is active, the saved data will not be released. When the application exits and restarts, the data saved on the device will be restored. 346 347The saved data will be released in the following cases: 348 349- The data is stored for more than 24 hours. 350- The application has been uninstalled. 351- Data is successfully restored. 352 353**System capability**: SystemCapability.DistributedDataManager.DataObject.DistributedObject 354 355**Parameters** 356 357| Name| Type| Mandatory| Description| 358| -------- | -------- | -------- | -------- | 359| deviceId | string | Yes| ID of the device where data is stored. The value **local** indicates the local device.| 360| callback | AsyncCallback<[SaveSuccessResponse](#savesuccessresponse9)> | Yes| Callback invoked to return **SaveSuccessResponse**, which contains information such as session ID, version, and device ID.| 361 362**Example** 363 364```ts 365g_object.setSessionId("123456"); 366g_object.save("local", (err, result) => { 367 if (err) { 368 console.info("save failed, error code = " + err.code); 369 console.info("save failed, error message: " + err.message); 370 return; 371 } 372 console.info("save callback"); 373 console.info("save sessionId: " + result.sessionId); 374 console.info("save version: " + result.version); 375 console.info("save deviceId: " + result.deviceId); 376}); 377``` 378 379### save<sup>9+</sup> 380 381save(deviceId: string): Promise<SaveSuccessResponse> 382 383Saves a distributed data object. This API uses a promise to return the result. 384 385If the application is active, the saved data will not be released. When the application exits and restarts, the data saved on the device will be restored. 386 387The saved data will be released in the following cases: 388 389- The data is stored for more than 24 hours. 390- The application has been uninstalled. 391- Data is successfully restored. 392 393**System capability**: SystemCapability.DistributedDataManager.DataObject.DistributedObject 394 395**Parameters** 396 397| Name| Type| Mandatory| Description| 398| -------- | -------- | -------- | -------- | 399| deviceId | string | Yes| ID of the device where the data is saved. The default value is **local**, which indicates the local device. | 400 401**Return value** 402 403| Type| Description| 404| -------- | -------- | 405| Promise<[SaveSuccessResponse](#savesuccessresponse9)> | Promise used to return **SaveSuccessResponse**, which contains information such as session ID, version, and device ID.| 406 407**Example** 408 409```js 410g_object.setSessionId("123456"); 411g_object.save("local").then((result) => { 412 console.info("save callback"); 413 console.info("save sessionId " + result.sessionId); 414 console.info("save version " + result.version); 415 console.info("save deviceId " + result.deviceId); 416}).catch((err) => { 417 console.info("save failed, error code = " + err.code); 418 console.info("save failed, error message: " + err.message); 419}); 420``` 421 422### revokeSave<sup>9+</sup> 423 424revokeSave(callback: AsyncCallback<RevokeSaveSuccessResponse>): void 425 426Revokes the saving operation of this distributed data object. This API uses an asynchronous callback to return the result. 427 428If the object is saved on the local device, the data saved on all trusted devices will be deleted. 429If the object is stored on another device, the data on the local device will be deleted. 430 431**System capability**: SystemCapability.DistributedDataManager.DataObject.DistributedObject 432 433**Parameters** 434 435| Name| Type| Mandatory| Description| 436| -------- | -------- | -------- | -------- | 437| callback | AsyncCallback<[RevokeSaveSuccessResponse](#revokesavesuccessresponse9)> | Yes| Callback invoked to return **RevokeSaveSuccessResponse**, which contains the session ID.| 438 439**Example** 440 441```js 442g_object.setSessionId("123456"); 443// Save data for persistence. 444g_object.save("local", (err, result) => { 445 if (err) { 446 console.info("save failed, error code = " + err.code); 447 console.info("save failed, error message: " + err.message); 448 return; 449 } 450 console.info("save callback"); 451 console.info("save sessionId: " + result.sessionId); 452 console.info("save version: " + result.version); 453 console.info("save deviceId: " + result.deviceId); 454}); 455// Delete the persistence data. 456g_object.revokeSave((err, result) => { 457 if (err) { 458 console.info("revokeSave failed, error code = " + err.code); 459 console.info("revokeSave failed, error message: " + err.message); 460 return; 461 } 462 console.info("revokeSave callback"); 463 console.info("revokeSave sessionId " + result.sessionId); 464}); 465``` 466 467### revokeSave<sup>9+</sup> 468 469revokeSave(): Promise<RevokeSaveSuccessResponse> 470 471Revokes the saving operation of this distributed data object. This API uses a promise to return the result. 472 473If the object is saved on the local device, the data saved on all trusted devices will be deleted. 474If the object is stored on another device, the data on the local device will be deleted. 475 476**System capability**: SystemCapability.DistributedDataManager.DataObject.DistributedObject 477 478**Return value** 479 480| Type| Description| 481| -------- | -------- | 482| Promise<[RevokeSaveSuccessResponse](#revokesavesuccessresponse9)> | Promise used to return **RevokeSaveSuccessResponse**, which contains the session ID.| 483 484**Example** 485 486```ts 487g_object.setSessionId("123456"); 488// Save data for persistence. 489g_object.save("local").then((result) => { 490 console.info("save callback"); 491 console.info("save sessionId " + result.sessionId); 492 console.info("save version " + result.version); 493 console.info("save deviceId " + result.deviceId); 494}).catch((err) => { 495 console.info("save failed, error code = " + err.code); 496 console.info("save failed, error message: " + err.message); 497}); 498// Delete the persistence data. 499g_object.revokeSave().then((result) => { 500 console.info("revokeSave callback"); 501 console.info("sessionId" + result.sessionId); 502}).catch((err)=> { 503 console.info("revokeSave failed, error code = " + err.code); 504 console.info("revokeSave failed, error message = " + err.message); 505}); 506``` 507 508## distributedObject.createDistributedObject<sup>(deprecated)</sup> 509 510createDistributedObject(source: object): DistributedObject 511 512 513Creates a distributed data object. 514 515> **NOTE** 516> 517> This API is supported since API version 8 and deprecated since API version 9. You are advised to use **distributedObject.create**. 518 519**System capability**: SystemCapability.DistributedDataManager.DataObject.DistributedObject 520 521**Parameters** 522 523| Name| Type| Mandatory| Description| 524| -------- | -------- | -------- | -------- | 525| source | object | Yes| Attributes of the distributed data object.| 526 527**Return value** 528 529| Type| Description| 530| -------- | -------- | 531| [DistributedObject](#distributedobjectdeprecated) | Distributed data object created.| 532 533**Example** 534 535```js 536import distributedObject from '@ohos.data.distributedDataObject'; 537// Create a distributed data object, which contains attributes of the string, number, boolean, and object types. 538let g_object = distributedObject.createDistributedObject({name:"Amy", age:18, isVis:false, parent:{mother:"jack mom",father:"jack Dad"}}); 539``` 540 541## DistributedObject<sup>(deprecated)</sup> 542 543Provides APIs for managing a distributed data object. Before using any API of this class, use [createDistributedObject()](#distributedobjectcreatedistributedobjectdeprecated) to create a **DistributedObject** object. 544 545### setSessionId<sup>(deprecated)</sup> 546 547setSessionId(sessionId?: string): boolean 548 549Sets a session ID for synchronization. Automatic synchronization is performed for multiple devices with the same session ID on a trusted network. 550 551> **NOTE** 552> 553> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [setSessionId](#setsessionid9). 554 555**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC 556 557**System capability**: SystemCapability.DistributedDataManager.DataObject.DistributedObject 558 559**Parameters** 560 561| Name| Type| Mandatory| Description| 562| -------- | -------- | -------- | -------- | 563| sessionId | string | No| ID of a distributed data object on a trusted network. To remove a distributed data object from the network, set this parameter to "" or leave it empty.| 564 565**Return value** 566 567| Type| Description| 568| -------- | -------- | 569| boolean | Returns **true** if the session ID is set successfully;<br>returns **false** otherwise. | 570 571**Example** 572 573```js 574import distributedObject from '@ohos.data.distributedDataObject'; 575let g_object = distributedObject.createDistributedObject({name:"Amy", age:18, isVis:false, parent:{mother:"jack mom",father:"jack Dad"}});; 576// Add g_object to the distributed network. 577g_object.setSessionId(distributedObject.genSessionId()); 578// Remove g_object from the distributed network. 579g_object.setSessionId(""); 580``` 581 582### on('change')<sup>(deprecated)</sup> 583 584on(type: 'change', callback: Callback<{ sessionId: string, fields: Array<string> }>): void 585 586Subscribes to data changes of this distributed data object. 587 588> **NOTE** 589> 590> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [on('change')](#onchange9). 591 592**System capability**: SystemCapability.DistributedDataManager.DataObject.DistributedObject 593 594**Parameters** 595 596| Name| Type| Mandatory| Description| 597| -------- | -------- | -------- | -------- | 598| type | string | Yes| Event type to subscribe to. The value is **change**, which indicates data changes.| 599| callback | Callback<{ sessionId: string, fields: Array<string> }> | Yes| Callback invoked to return the changes of the distributed data object.<br>**sessionId** indicates the session ID of the distributed data object.<br>**fields** indicates the changed attributes of the distributed data object.| 600 601**Example** 602 603```js 604import distributedObject from '@ohos.data.distributedDataObject'; 605let g_object = distributedObject.createDistributedObject({name:"Amy", age:18, isVis:false, parent:{mother:"jack mom",father:"jack Dad"}}); 606globalThis.changeCallback = (sessionId, changeData) => { 607 console.info("change" + sessionId); 608 if (changeData != null && changeData != undefined) { 609 changeData.forEach(element => { 610 console.info("changed !" + element + " " + g_object[element]); 611 }); 612 } 613} 614g_object.on("change", globalThis.changeCallback); 615``` 616 617### off('change')<sup>(deprecated)</sup> 618 619off(type: 'change', callback?: Callback<{ sessionId: string, fields: Array<string> }>): void 620 621Unsubscribes from the data changes of this distributed data object. 622 623> **NOTE** 624> 625> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [off('change')](#offchange9). 626 627**System capability**: SystemCapability.DistributedDataManager.DataObject.DistributedObject 628 629**Parameters** 630 631| Name| Type| Mandatory| Description| 632| -------- | -------- | -------- | -------- | 633| type | string | Yes| Event type to unsubscribe from. The value is **change**, which indicates data changes.| 634| callback | Callback<{ sessionId: string, fields: Array<string> }> | 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.| 635 636 637**Example** 638 639```js 640import distributedObject from '@ohos.data.distributedDataObject'; 641let g_object = distributedObject.createDistributedObject({name:"Amy", age:18, isVis:false, parent:{mother:"jack mom",father:"jack Dad"}}); 642// Unregister the specified data change callback. 643g_object.off("change", globalThis.changeCallback); 644// Unregister all data change callbacks. 645g_object.off("change"); 646``` 647 648### on('status')<sup>(deprecated)</sup> 649 650on(type: 'status', callback: Callback<{ sessionId: string, networkId: string, status: 'online' | 'offline' }>): void 651 652Subscribes to status changes of this distributed data object. 653 654> **NOTE** 655> 656> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [on('status')](#onstatus9). 657 658**System capability**: SystemCapability.DistributedDataManager.DataObject.DistributedObject 659 660**Parameters** 661 662| Name| Type| Mandatory| Description| 663| -------- | -------- | -------- | -------- | 664| type | string | Yes| Event type to subscribe to. The value is **status**, which indicates the status change (online or offline) of the distributed data object.| 665| callback | Callback<{ sessionId: string, networkId: string, status: 'online' \| 'offline' }> | Yes| Callback invoked to return the status change.<br>**sessionId** indicates the session ID of the distributed data object.<br>**networkId** indicates the object device ID, that is, **deviceId**.<br>**status** indicates the object status, which can be online or offline.| 666 667**Example** 668 669```js 670import distributedObject from '@ohos.data.distributedDataObject'; 671globalThis.statusCallback = (sessionId, networkId, status) => { 672 globalThis.response += "status changed " + sessionId + " " + status + " " + networkId; 673} 674let g_object = distributedObject.createDistributedObject({name:"Amy", age:18, isVis:false, parent:{mother:"jack mom",father:"jack Dad"}}); 675g_object.on("status", globalThis.statusCallback); 676``` 677 678### off('status')<sup>(deprecated)</sup> 679 680off(type: 'status', callback?: Callback<{ sessionId: string, deviceId: string, status: 'online' | 'offline' }>): void 681 682Unsubscribes from the status change of this distributed data object. 683 684> **NOTE** 685> 686> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [off('status')](#offstatus9). 687 688**System capability**: SystemCapability.DistributedDataManager.DataObject.DistributedObject 689 690**Parameters** 691 692| Name| Type| Mandatory| Description| 693| -------- | -------- | -------- | -------- | 694| type | string | Yes| Event type to unsubscribe from. The value is **status**, which indicates the status change (online or offline) of the distributed data object.| 695| callback | Callback<{ sessionId: string, deviceId: string, status: 'online' \| 'offline' }> | No| Callback for status changes. If this parameter is not specified, all status change callbacks of this distributed data object will be unregistered.<br>**sessionId** indicates the session ID of the distributed data object.<br>**deviceId** indicates the device ID of the distributed data object.<br>**status** indicates the object status, which can be online or offline.| 696 697 698**Example** 699 700```js 701import distributedObject from '@ohos.data.distributedDataObject'; 702let g_object = distributedObject.createDistributedObject({name:"Amy", age:18, isVis:false, parent:{mother:"jack mom",father:"jack Dad"}}); 703globalThis.statusCallback = (sessionId, networkId, status) => { 704 globalThis.response += "status changed " + sessionId + " " + status + " " + networkId; 705} 706// Unregister the specified status change callback. 707g_object.off("status",globalThis.statusCallback); 708// Unregister all status change callbacks. 709g_object.off("status"); 710``` 711