1# CommonEventSubscriber 2 3The **CommonEventSubscriber** module provides APIs for describing the common event subscriber. 4 5> **NOTE** 6> 7> The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version. 8 9## Usage 10 11Before using the **CommonEventSubscriber** module, you must obtain a **subscriber** object by calling **CommonEvent.createSubscriber**. 12 13```ts 14import CommonEvent from '@ohos.commonEvent'; 15import CommonEventManager from '@ohos.commonEventManager'; 16import Base from '@ohos.base'; 17let subscriber:CommonEventManager.CommonEventSubscriber; // Used to save the created subscriber object for subsequent subscription and unsubscription. 18 19// Subscriber information. 20let subscribeInfo:CommonEventManager.CommonEventSubscribeInfo = { 21 events: ["event"] 22}; 23 24// Callback for subscriber creation. 25function createCB(err:Base.BusinessError, commonEventSubscriber:CommonEventManager.CommonEventSubscriber) { 26 if (err.code !== undefined && err.code != null) { 27 console.error(`createSubscriber failed, code is ${err.code}`); 28 } else { 29 console.info("createSubscriber"); 30 subscriber = commonEventSubscriber; 31 } 32} 33 34// Create a subscriber. 35CommonEvent.createSubscriber(subscribeInfo, createCB); 36``` 37 38## getCode 39 40getCode(callback: AsyncCallback\<number>): void 41 42Obtains the code of this common event. This API uses an asynchronous callback to return the result. 43 44**System capability**: SystemCapability.Notification.CommonEvent 45 46**Parameters** 47 48| Name | Type | Mandatory| Description | 49| -------- | ---------------------- | ---- | ------------------ | 50| callback | AsyncCallback\<number\> | Yes | Common event code.| 51 52**Example** 53 54```ts 55// Callback for result code obtaining of an ordered common event. 56function getCodeCB(err:Base.BusinessError, code:number) { 57 if (err.code !== undefined && err.code != null) { 58 console.error(`getCode failed, code is ${err.code}, message is ${err.message}`); 59 } else { 60 console.info("getCode " + JSON.stringify(code)); 61 } 62} 63subscriber.getCode(getCodeCB); 64``` 65 66## getCode 67 68getCode(): Promise\<number> 69 70Obtains the code of this common event. This API uses a promise to return the result. 71 72**System capability**: SystemCapability.Notification.CommonEvent 73 74**Return value** 75 76| Type | Description | 77| ---------------- | -------------------- | 78| Promise\<number> | Common event code.| 79 80**Example** 81 82```ts 83subscriber.getCode().then((code:number) => { 84 console.info("getCode " + JSON.stringify(code)); 85}).catch((err:Base.BusinessError) => { 86 console.error(`getCode failed, code is ${err.code}, message is ${err.message}`); 87}); 88``` 89 90## getCodeSync<sup>10+</sup> 91 92getCodeSync(): number 93 94Obtains the code of this common event. This API returns the result synchronously. 95 96**System capability**: SystemCapability.Notification.CommonEvent 97 98**Return value** 99 100| Type | Description | 101| ---------------- | -------------------- | 102| number | Common event code.| 103 104**Example** 105 106```ts 107let code = subscriber.getCodeSync(); 108console.info("getCodeSync " + JSON.stringify(code)); 109``` 110 111## setCode 112 113setCode(code: number, callback: AsyncCallback\<void>): void 114 115Sets the code for this common event. This API uses an asynchronous callback to return the result. 116 117**System capability**: SystemCapability.Notification.CommonEvent 118 119**Parameters** 120 121| Name | Type | Mandatory| Description | 122| -------- | -------------------- | ---- | ---------------------- | 123| code | number | Yes | Common event code. | 124| callback | AsyncCallback\<void> | Yes | Callback used to return the result.| 125 126**Example** 127 128```ts 129// Callback for result code setting of an ordered common event. 130function setCodeCB(err:Base.BusinessError) { 131 if (err.code !== undefined && err.code != null) { 132 console.error(`setCode failed, code is ${err.code}, message is ${err.message}`); 133 } else { 134 console.info("setCode"); 135 } 136} 137subscriber.setCode(1, setCodeCB); 138``` 139 140## setCode 141 142setCode(code: number): Promise\<void> 143 144Sets the code for this common event. This API uses a promise to return the result. 145 146**System capability**: SystemCapability.Notification.CommonEvent 147 148**Parameters** 149 150| Name| Type | Mandatory| Description | 151| ------ | ------ | ---- | ------------------ | 152| code | number | Yes | Common event code.| 153 154**Return value** 155 156| Type | Description | 157| ---------------- | -------------------- | 158| Promise\<void> | Promise used to return the result.| 159 160**Example** 161 162```ts 163subscriber.setCode(1).then(() => { 164 console.info("setCode"); 165}).catch((err:Base.BusinessError) => { 166 console.error(`setCode failed, code is ${err.code}, message is ${err.message}`); 167}); 168``` 169 170## setCodeSync<sup>10+</sup> 171 172setCodeSync(code: number): void 173 174Sets the code for this common event. This API returns the result synchronously. 175 176**System capability**: SystemCapability.Notification.CommonEvent 177 178**Parameters** 179 180| Name| Type | Mandatory| Description | 181| ------ | ------ | ---- | ------------------ | 182| code | number | Yes | Common event code.| 183 184 185**Example** 186 187```ts 188 189try { 190 subscriber.setCodeSync(1); 191} catch (error) { 192 let err:Base.BusinessError = error as Base.BusinessError; 193 console.error(`setCodeSync failed, code is ${err.code}, message is ${err.message}`); 194} 195``` 196 197## getData 198 199getData(callback: AsyncCallback\<string>): void 200 201Obtains the data of this common event. This API uses an asynchronous callback to return the result. 202 203**System capability**: SystemCapability.Notification.CommonEvent 204 205**Parameters** 206 207| Name | Type | Mandatory| Description | 208| -------- | ---------------------- | ---- | -------------------- | 209| callback | AsyncCallback\<string> | Yes | Common event data.| 210 211**Example** 212 213```ts 214// Callback for result data obtaining of an ordered common event. 215function getDataCB(err:Base.BusinessError, data:string) { 216 if (err.code !== undefined && err.code != null) { 217 console.error(`getData failed, code is ${err.code}, message is ${err.message}`); 218 } else { 219 console.info("getData " + JSON.stringify(data)); 220 } 221} 222subscriber.getData(getDataCB); 223``` 224 225## getData 226 227getData(): Promise\<string> 228 229Obtains the data of this common event. This API uses a promise to return the result. 230 231**System capability**: SystemCapability.Notification.CommonEvent 232 233**Return value** 234 235| Type | Description | 236| ---------------- | ------------------ | 237| Promise\<string> | Common event data.| 238 239**Example** 240 241```ts 242subscriber.getData().then((data:string) => { 243 console.info("getData " + JSON.stringify(data)); 244}).catch((err:Base.BusinessError) => { 245 console.error(`getData failed, code is ${err.code}, message is ${err.message}`); 246}); 247``` 248 249## getDataSync<sup>10+</sup> 250 251getDataSync(): string 252 253Obtains the data of this common event. This API returns the result synchronously. 254 255**System capability**: SystemCapability.Notification.CommonEvent 256 257**Return value** 258 259| Type | Description | 260| ---------------- | ------------------ | 261| string | Common event data.| 262 263**Example** 264 265```ts 266let data = subscriber.getDataSync(); 267console.info("getDataSync " + JSON.stringify(data)); 268``` 269 270## setData 271 272setData(data: string, callback: AsyncCallback\<void>): void 273 274Sets the data for this common event. This API uses an asynchronous callback to return the result. 275 276**System capability**: SystemCapability.Notification.CommonEvent 277 278**Parameters** 279 280| Name | Type | Mandatory| Description | 281| -------- | -------------------- | ---- | -------------------- | 282| data | string | Yes | Common event data. | 283| callback | AsyncCallback\<void> | Yes | Callback used to return the result.| 284 285**Example** 286 287```ts 288// Callback for result data setting of an ordered common event 289function setDataCB(err:Base.BusinessError) { 290 if (err.code !== undefined && err.code != null) { 291 console.error(`setCode failed, code is ${err.code}, message is ${err.message}`); 292 } else { 293 console.info("setData"); 294 } 295} 296subscriber.setData("publish_data_changed", setDataCB); 297``` 298 299## setData 300 301setData(data: string): Promise\<void> 302 303Sets the data for this common event. This API uses a promise to return the result. 304 305**System capability**: SystemCapability.Notification.CommonEvent 306 307**Parameters** 308 309| Name| Type | Mandatory| Description | 310| ------ | ------ | ---- | -------------------- | 311| data | string | Yes | Common event data.| 312 313**Return value** 314 315| Type | Description | 316| ---------------- | -------------------- | 317| Promise\<void> | Promise used to return the result.| 318 319**Example** 320 321```ts 322subscriber.setData("publish_data_changed").then(() => { 323 console.info("setData"); 324}).catch((err:Base.BusinessError) => { 325 console.error(`setCode failed, code is ${err.code}, message is ${err.message}`); 326}); 327``` 328 329## setDataSync<sup>10+</sup> 330 331setDataSync(data: string): void 332 333Sets the data for this common event. This API returns the result synchronously. 334 335**System capability**: SystemCapability.Notification.CommonEvent 336 337**Parameters** 338 339| Name| Type | Mandatory| Description | 340| ------ | ------ | ---- | -------------------- | 341| data | string | Yes | Common event data.| 342 343**Example** 344 345```ts 346try { 347 subscriber.setDataSync("publish_data_changed"); 348} catch (error) { 349 let err:Base.BusinessError = error as Base.BusinessError; 350 console.error(`setDataSync failed, code is ${err.code}, message is ${err.message}`); 351} 352``` 353 354## setCodeAndData 355 356setCodeAndData(code: number, data: string, callback:AsyncCallback\<void>): void 357 358Sets the code and data for this common event. This API uses an asynchronous callback to return the result. 359 360**System capability**: SystemCapability.Notification.CommonEvent 361 362**Parameters** 363 364| Name | Type | Mandatory| Description | 365| -------- | -------------------- | ---- | ---------------------- | 366| code | number | Yes | Common event code. | 367| data | string | Yes | Common event data. | 368| callback | AsyncCallback\<void> | Yes | Callback used to return the result.| 369 370**Example** 371 372```ts 373// Callback for code and data setting of an ordered common event. 374function setCodeDataCB(err:Base.BusinessError) { 375 if (err.code !== undefined && err.code != null) { 376 console.error(`setCodeAndData failed, code is ${err.code}, message is ${err.message}`); 377 } else { 378 console.info("setCodeDataCallback"); 379 } 380} 381subscriber.setCodeAndData(1, "publish_data_changed", setCodeDataCB); 382``` 383 384## setCodeAndData 385 386setCodeAndData(code: number, data: string): Promise\<void> 387 388Sets the code and data for this common event. This API uses a promise to return the result. 389 390**System capability**: SystemCapability.Notification.CommonEvent 391 392**Parameters** 393 394| Name| Type | Mandatory| Description | 395| ------ | ------ | ---- | -------------------- | 396| code | number | Yes | Common event code.| 397| data | string | Yes | Common event data.| 398 399**Return value** 400 401| Type | Description | 402| ---------------- | -------------------- | 403| Promise\<void> | Promise used to return the result.| 404 405**Example** 406 407```ts 408subscriber.setCodeAndData(1, "publish_data_changed").then(() => { 409 console.info("setCodeAndData"); 410}).catch((err:Base.BusinessError) => { 411 console.error(`setCodeAndData failed, code is ${err.code}, message is ${err.message}`); 412}); 413``` 414 415## setCodeAndDataSync<sup>10+</sup> 416 417setCodeAndDataSync(code: number, data: string): void 418 419Sets the code and data for this common event. This API returns the result synchronously. 420 421**System capability**: SystemCapability.Notification.CommonEvent 422 423**Parameters** 424 425| Name| Type | Mandatory| Description | 426| ------ | ------ | ---- | -------------------- | 427| code | number | Yes | Common event code.| 428| data | string | Yes | Common event data.| 429 430**Example** 431 432```ts 433try { 434 subscriber.setCodeAndDataSync(1, "publish_data_changed"); 435} catch (error) { 436 let err:Base.BusinessError = error as Base.BusinessError; 437 console.error(`setCodeAndData failed, code is ${err.code}, message is ${err.message}`); 438} 439 440``` 441## isOrderedCommonEvent 442 443isOrderedCommonEvent(callback: AsyncCallback\<boolean>): void 444 445Checks whether this common event is an ordered one. This API uses an asynchronous callback to return the result. 446 447**System capability**: SystemCapability.Notification.CommonEvent 448 449**Parameters** 450 451| Name | Type | Mandatory| Description | 452| -------- | ----------------------- | ---- | ---------------------------------- | 453| callback | AsyncCallback\<boolean> | Yes | Returns **true** if the common event is an ordered one; returns **false** otherwise.| 454 455**Example** 456 457```ts 458// Callback for checking whether the current common event is an ordered one. 459function isOrderedCB(err:Base.BusinessError, isOrdered:boolean) { 460 if (err.code !== undefined && err.code != null) { 461 console.error(`isOrderedCommonEvent failed, code is ${err.code}, message is ${err.message}`); 462 } else { 463 console.info("isOrdered " + JSON.stringify(isOrdered)); 464 } 465} 466subscriber.isOrderedCommonEvent(isOrderedCB); 467``` 468 469## isOrderedCommonEvent 470 471isOrderedCommonEvent(): Promise\<boolean> 472 473Checks whether this common event is an ordered one. This API uses a promise to return the result. 474 475**System capability**: SystemCapability.Notification.CommonEvent 476 477**Return value** 478 479| Type | Description | 480| ----------------- | -------------------------------- | 481| Promise\<boolean> | Returns **true** if the common event is an ordered one; returns **false** otherwise.| 482 483**Example** 484 485```ts 486subscriber.isOrderedCommonEvent().then((isOrdered:boolean) => { 487 console.info("isOrdered " + JSON.stringify(isOrdered)); 488}).catch((err:Base.BusinessError) => { 489 console.error(`isOrdered failed, code is ${err.code}, message is ${err.message}`); 490}); 491``` 492 493## isOrderedCommonEventSync<sup>10+</sup> 494 495isOrderedCommonEventSync(): boolean 496 497Checks whether this common event is an ordered one. This API returns the result synchronously. 498 499**System capability**: SystemCapability.Notification.CommonEvent 500 501**Return value** 502 503| Type | Description | 504| ----------------- | -------------------------------- | 505| boolean | Returns **true** if the common event is an ordered one; returns **false** otherwise.| 506 507**Example** 508 509```ts 510let isOrdered = subscriber.isOrderedCommonEventSync(); 511console.info("isOrdered " + JSON.stringify(isOrdered)); 512``` 513 514## isStickyCommonEvent 515 516isStickyCommonEvent(callback: AsyncCallback\<boolean>): void 517 518Checks whether this common event is a sticky one. This API uses an asynchronous callback to return the result. 519 520**System capability**: SystemCapability.Notification.CommonEvent 521 522**Parameters** 523 524| Name | Type | Mandatory| Description | 525| -------- | ----------------------- | ---- | ---------------------------------- | 526| callback | AsyncCallback\<boolean> | Yes | Returns **true** if the common event is a sticky one; returns **false** otherwise.| 527 528**Example** 529 530```ts 531// Callback for checking whether the current common event is a sticky one. 532function isStickyCB(err:Base.BusinessError, isSticky:boolean) { 533 if (err.code !== undefined && err.code != null) { 534 console.error(`isStickyCommonEvent failed, code is ${err.code}, message is ${err.message}`); 535 } else { 536 console.info("isSticky " + JSON.stringify(isSticky)); 537 } 538} 539subscriber.isStickyCommonEvent(isStickyCB); 540``` 541 542## isStickyCommonEvent 543 544isStickyCommonEvent(): Promise\<boolean> 545 546Checks whether this common event is a sticky one. This API uses a promise to return the result. 547 548**System capability**: SystemCapability.Notification.CommonEvent 549 550**Return value** 551 552| Type | Description | 553| ----------------- | -------------------------------- | 554| Promise\<boolean> | Returns **true** if the common event is a sticky one; returns **false** otherwise.| 555 556**Example** 557 558```ts 559subscriber.isStickyCommonEvent().then((isSticky:boolean) => { 560 console.info("isSticky " + JSON.stringify(isSticky)); 561}).catch((err:Base.BusinessError) => { 562 console.error(`isSticky failed, code is ${err.code}, message is ${err.message}`); 563}); 564``` 565 566## isStickyCommonEventSync<sup>10+</sup> 567 568isStickyCommonEventSync(): boolean 569 570Checks whether this common event is a sticky one. This API returns the result synchronously. 571 572**System capability**: SystemCapability.Notification.CommonEvent 573 574**Return value** 575 576| Type | Description | 577| ----------------- | -------------------------------- | 578| boolean | Returns **true** if the common event is a sticky one; returns **false** otherwise.| 579 580**Example** 581 582```ts 583let isSticky = subscriber.isStickyCommonEventSync(); 584console.info("isSticky " + JSON.stringify(isSticky)); 585``` 586 587## abortCommonEvent 588 589abortCommonEvent(callback: AsyncCallback\<void>): void 590 591Aborts this common event. After the abort, the common event is not sent to the next subscriber. This API takes effect only for ordered common events. It uses an asynchronous callback to return the result. 592 593**System capability**: SystemCapability.Notification.CommonEvent 594 595**Parameters** 596 597| Name | Type | Mandatory| Description | 598| -------- | -------------------- | ---- | -------------------- | 599| callback | AsyncCallback\<void> | Yes | Callback used to return the result.| 600 601**Example** 602 603```ts 604// Callback for common event aborting. 605function abortCB(err:Base.BusinessError) { 606 if (err.code !== undefined && err.code != null) { 607 console.error(`abortCommonEvent failed, code is ${err.code}, message is ${err.message}`); 608 } else { 609 console.info("abortCommonEvent"); 610 } 611} 612subscriber.abortCommonEvent(abortCB); 613``` 614 615## abortCommonEvent 616 617abortCommonEvent(): Promise\<void> 618 619Aborts this common event. After the abort, the common event is not sent to the next subscriber. This API takes effect only for ordered common events. It uses a promise to return the result. 620 621**System capability**: SystemCapability.Notification.CommonEvent 622 623**Return value** 624 625| Type | Description | 626| ---------------- | -------------------- | 627| Promise\<void> | Promise used to return the result.| 628 629**Example** 630 631```ts 632subscriber.abortCommonEvent().then(() => { 633 console.info("abortCommonEvent"); 634}).catch((err:Base.BusinessError) => { 635 console.error(`abortCommonEvent failed, code is ${err.code}, message is ${err.message}`); 636}); 637``` 638 639## abortCommonEventSync<sup>10+</sup> 640 641abortCommonEventSync(): void 642 643Aborts this common event. After the abort, the common event is not sent to the next subscriber. This API returns the result synchronously. 644 645**System capability**: SystemCapability.Notification.CommonEvent 646 647**Example** 648 649```ts 650subscriber.abortCommonEventSync(); 651``` 652 653## clearAbortCommonEvent 654 655clearAbortCommonEvent(callback: AsyncCallback\<void>): void 656 657Clears the aborted state of this common event. This API takes effect only for ordered common events. It uses an asynchronous callback to return the result. 658 659**System capability**: SystemCapability.Notification.CommonEvent 660 661**Parameters** 662 663| Name | Type | Mandatory| Description | 664| -------- | -------------------- | ---- | -------------------- | 665| callback | AsyncCallback\<void> | Yes | Callback used to return the result.| 666 667**Example** 668 669```ts 670// Callback for clearing the aborted state of the current common event. 671function clearAbortCB(err:Base.BusinessError) { 672 if (err.code !== undefined && err.code != null) { 673 console.error(`clearAbortCommonEvent failed, code is ${err.code}, message is ${err.message}`); 674 } else { 675 console.info("clearAbortCommonEvent"); 676 } 677} 678subscriber.clearAbortCommonEvent(clearAbortCB); 679``` 680 681## clearAbortCommonEvent 682 683clearAbortCommonEvent(): Promise\<void> 684 685Clears the aborted state of this common event. This API takes effect only for ordered common events. It uses a promise to return the result. 686 687**System capability**: SystemCapability.Notification.CommonEvent 688 689**Return value** 690 691| Type | Description | 692| ---------------- | -------------------- | 693| Promise\<void> | Promise used to return the result.| 694 695**Example** 696 697```ts 698subscriber.clearAbortCommonEvent().then(() => { 699 console.info("clearAbortCommonEvent"); 700}).catch((err:Base.BusinessError) => { 701 console.error(`clearAbortCommonEvent failed, code is ${err.code}, message is ${err.message}`); 702}); 703``` 704 705## clearAbortCommonEventSync<sup>10+</sup> 706 707clearAbortCommonEventSync(): void 708 709Clears the aborted state of this common event. This API returns the result synchronously. 710 711**System capability**: SystemCapability.Notification.CommonEvent 712 713**Example** 714 715```ts 716subscriber.clearAbortCommonEventSync(); 717``` 718 719## getAbortCommonEvent 720 721getAbortCommonEvent(callback: AsyncCallback\<boolean>): void 722 723Checks whether this common event is in the aborted state. This API takes effect only for ordered common events. It uses an asynchronous callback to return the result. 724 725**System capability**: SystemCapability.Notification.CommonEvent 726 727**Parameters** 728 729| Name | Type | Mandatory| Description | 730| -------- | ----------------------- | ---- | ---------------------------------- | 731| callback | AsyncCallback\<boolean> | Yes | Returns **true** if the ordered common event is in the aborted state; returns **false** otherwise.| 732 733**Example** 734 735```ts 736// Callback for checking whether the current common event is in the aborted state. 737function getAbortCB(err:Base.BusinessError, abortEvent:boolean) { 738 if (err.code !== undefined && err.code != null) { 739 console.error(`getAbortCommonEvent failed, code is ${err.code}, message is ${err.message}`); 740 } else { 741 console.info("abortCommonEvent " + abortEvent) 742 } 743} 744subscriber.getAbortCommonEvent(getAbortCB); 745``` 746 747## getAbortCommonEvent 748 749getAbortCommonEvent(): Promise\<boolean> 750 751Checks whether this common event is in the aborted state. This API takes effect only for ordered common events. It uses a promise to return the result. 752 753**System capability**: SystemCapability.Notification.CommonEvent 754 755**Return value** 756 757| Type | Description | 758| ----------------- | ---------------------------------- | 759| Promise\<boolean> | Returns **true** if the ordered common event is in the aborted state; returns **false** otherwise.| 760 761**Example** 762 763```ts 764subscriber.getAbortCommonEvent().then((abortEvent:boolean) => { 765 console.info("abortCommonEvent " + JSON.stringify(abortEvent)); 766}).catch((err:Base.BusinessError) => { 767 console.error(`getAbortCommonEvent failed, code is ${err.code}, message is ${err.message}`); 768}); 769``` 770 771## getAbortCommonEventSync<sup>10+</sup> 772 773getAbortCommonEventSync(): boolean 774 775Checks whether this common event is in the aborted state. This API returns the result synchronously. 776 777**System capability**: SystemCapability.Notification.CommonEvent 778 779**Return value** 780 781| Type | Description | 782| ----------------- | ---------------------------------- | 783| boolean | Returns **true** if the ordered common event is in the aborted state; returns **false** otherwise.| 784 785**Example** 786 787```ts 788let abortEvent = subscriber.getAbortCommonEventSync(); 789console.info("getAbortCommonEventSync " + JSON.stringify(abortEvent)); 790``` 791 792## getSubscribeInfo 793 794getSubscribeInfo(callback: AsyncCallback\<CommonEventSubscribeInfo>): void 795 796Obtains the subscriber information. This API uses an asynchronous callback to return the result. 797 798**System capability**: SystemCapability.Notification.CommonEvent 799 800**Parameters** 801 802| Name | Type | Mandatory| Description | 803| -------- | ------------------------------------------------------------ | ---- | ---------------------- | 804| callback | AsyncCallback\<[CommonEventSubscribeInfo](./js-apis-inner-commonEvent-commonEventSubscribeInfo.md)> | Yes | Callback used to return the subscriber information.| 805 806**Example** 807 808```ts 809// Callback for subscriber information obtaining. 810function getCB(err:Base.BusinessError, subscribeInfo:CommonEventManager.CommonEventSubscribeInfo) { 811 if (err.code !== undefined && err.code != null) { 812 console.error(`getSubscribeInfo failed, code is ${err.code}, message is ${err.message}`); 813 } else { 814 console.info("subscribeInfo " + JSON.stringify(subscribeInfo)); 815 } 816} 817subscriber.getSubscribeInfo(getCB); 818``` 819 820## getSubscribeInfo 821 822getSubscribeInfo(): Promise\<CommonEventSubscribeInfo> 823 824Obtains the subscriber information. This API uses a promise to return the result. 825 826**System capability**: SystemCapability.Notification.CommonEvent 827 828**Return value** 829 830| Type | Description | 831| ------------------------------------------------------------ | ---------------------- | 832| Promise\<[CommonEventSubscribeInfo](./js-apis-inner-commonEvent-commonEventSubscribeInfo.md)> | Promise used to return the subscriber information.| 833 834**Example** 835 836```ts 837subscriber.getSubscribeInfo().then((subscribeInfo:CommonEventManager.CommonEventSubscribeInfo) => { 838 console.info("subscribeInfo " + JSON.stringify(subscribeInfo)); 839}).catch((err:Base.BusinessError) => { 840 console.error(`getSubscribeInfo failed, code is ${err.code}, message is ${err.message}`); 841}); 842``` 843 844## getSubscribeInfoSync<sup>10+</sup> 845 846getSubscribeInfoSync(): CommonEventSubscribeInfo 847 848Obtains the subscriber information. This API returns the result synchronously. 849 850**System capability**: SystemCapability.Notification.CommonEvent 851 852**Return value** 853 854| Type | Description | 855| ------------------------------------------------------------ | ---------------------- | 856| [CommonEventSubscribeInfo](./js-apis-inner-commonEvent-commonEventSubscribeInfo.md) | Callback used to return the subscriber information.| 857 858**Example** 859 860```ts 861let subscribeInfo = subscriber.getSubscribeInfoSync(); 862console.info("subscribeInfo " + JSON.stringify(subscribeInfo)); 863``` 864 865## finishCommonEvent<sup>9+</sup> 866 867finishCommonEvent(callback: AsyncCallback\<void>): void 868 869Finishes this common event. This API takes effect only for ordered common events. It uses an asynchronous callback to return the result. 870 871**System capability**: SystemCapability.Notification.CommonEvent 872 873**Parameters** 874 875| Name | Type | Mandatory| Description | 876| -------- | -------------------- | ---- | -------------------------------- | 877| callback | AsyncCallback\<void> | Yes | Callback returned after the ordered common event is finished.| 878 879**Example** 880 881```ts 882// Callback for ordered common event finishing. 883function finishCB(err:Base.BusinessError) { 884 if (err.code !== undefined && err.code != null) { 885 console.error(`finishCommonEvent failed, code is ${err.code}, message is ${err.message}`); 886 } else { 887 console.info("FinishCommonEvent"); 888 } 889} 890 891subscriber.finishCommonEvent(finishCB); 892``` 893 894## finishCommonEvent<sup>9+</sup> 895 896finishCommonEvent(): Promise\<void> 897 898Finishes this common event. This API takes effect only for ordered common events. It uses a promise to return the result. 899 900**System capability**: SystemCapability.Notification.CommonEvent 901 902**Return value** 903 904| Type | Description | 905| ---------------- | -------------------- | 906| Promise\<void> | Promise used to return the result.| 907 908**Example** 909 910```ts 911subscriber.finishCommonEvent().then(() => { 912 console.info("FinishCommonEvent"); 913}).catch((err:Base.BusinessError) => { 914 console.error(`finishCommonEvent failed, code is ${err.code}, message is ${err.message}`); 915}); 916``` 917