如需在worker线程中使用我们sdk,可参考以下代码初始化:
const workerPort = worker.workerPort;
workerPort.onmessage = (e: MessageEvents) => {
switch (e.data.type) {
case 'initSDK':
let solarEngineConfig = new SolarEngineConfig();
SolarEngineManager.initialize(e.data.context, appkey,solarEngineConfig);
case 'lifecycle':
SolarEngineManager.trackAppLifeCycleEvent(e.data.event);
break;
}
//主线程注册生命周期事件(需先初始化sdk,然后注册生命周期事件)
workerInstance.postMessage({ type: 'initSDK', context: getContext() });
SolarEngineManager.registerAppLifeCycle(
getContext(),
(eventName: string) => {
// 3. 生命周期事件回传给 worker
workerInstance.postMessage({
type: 'lifecycle',
event: eventName
});
}