Skip to main content
Version: v3.x

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

PropertyTypeRequiredDefaultValueDescriptionAPI_LEVEL
stateobjectN-A data object mounted on the appService instance that can be used to store the current state of the service3.0
onInit(params?: string) => voidN-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 method3.0
onEvent(params?: string) => voidN-onEvent is used to listen for system events, and event-related parameters are passed through params3.0
onDestroy() => voidN-The onDestroy lifecycle function is triggered when the service is destroyed3.0

Result

TypeDescription
unknownAppService instance

Example

appService.js
AppService({
state: {
text: 'Hello Zepp OS',
},
onInit() {
console.log('onInit')
},
onEvent(event) {
console.log(event)
},
})