AppService
Start from API_LEVEL
3.0
. Please refer to API_LEVEL.
Register an App Service in the Mini Program, specify the lifecycle callback for the current App Service, etc. Each App Service file must call the AppService()
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 |
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')
},
})