AppService
Start from API_LEVEL
3.0. Please refer to API_LEVEL.
Register a page in the Mini Program, specify the lifecycle callback for the current page, etc. Each page file must call the Page() constructor only once.
info
permission code: device:os.bg_service
Type
function AppService(option: Option): Result
Parameters
Option
| Property | Type | Required | DefaultValue | Description | API_LEVEL |
|---|---|---|---|---|---|
| state | object | N | - | A data object mounted on the appService instance that can be used to store the current state of the service | 3.0 |
| onInit | (params?: string) => void | N | - | This function is triggered when the service is started. If the service is started with params, the params string can be obtained in the onInit method | 3.0 |
| onEvent | (params?: string) => void | N | - | onEvent is used to listen for system events, and event-related parameters are passed through params | 3.0 |
| onDestroy | () => void | N | - | The onDestroy lifecycle function is triggered when the service is destroyed | 3.0 |
Result
| Type | Description |
|---|---|
unknown | AppService instance |
Example
appService.js
AppService({
state: {
text: 'Hello Zepp OS',
},
onInit() {
console.log('onInit')
},
onEvent(event) {
console.log(event)
},
})