Skip to main content
Version: v3+

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​

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
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')
},
})