Callbacks from background service to mini program #407
-
Hello. I implemented a mini program and a background service. When I update the settings in the mini program, I am able to send events from the mini program to the background service with I do not want to trigger a notification. I just want to send back from the background service to the UI (when it is open only) a status message. Is this even possible? Thank you. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Create an instance of LocalStorage in // app.js
import { LocalStorage } from "@zos/storage";
App({
globals: { storage: new LocalStorage() },
onCreate() {},
onDestroy() {}
})
// device/bg
const storage = getApp().globals.storage; |
Beta Was this translation helpful? Give feedback.
-
This was really helpful. I forgot about the global app object as described in https://docs.zepp.com/docs/guides/best-practice/cross-page-communications/ I added the EventBus in the global app object and now I can emit events from the service back to the UI:
Thank you for your hint. |
Beta Was this translation helpful? Give feedback.
Create an instance of LocalStorage in
app.js
. Then use it as a global object in device/bg context.