@@ -21,12 +21,9 @@ type SAFlutterPluginCallMap = Map<string, string | boolean | number | Array<stri
2121/** SensorsAnalyticsFlutterPlugin **/
2222export default class SensorsAnalyticsFlutterPlugin implements FlutterPlugin, MethodCallHandler {
2323 private channel: MethodChannel | null = null;
24- private context: Context | null = null;
24+ private applicationContext: common. Context | null = null;
2525 private moduleManager: SAFlutterManager = new SAFlutterManager();
2626
27- constructor() {
28- }
29-
3027 getUniqueClassName(): string {
3128 return "SensorsAnalyticsFlutterPlugin"
3229 }
@@ -36,7 +33,7 @@ export default class SensorsAnalyticsFlutterPlugin implements FlutterPlugin, Met
3633 this.channel.setMethodCallHandler(this)
3734 // 调试出现过 getContext(this) 无法取到结果
3835 // 如果使用 ApplicationContext,原生 $AppEnd 和 $AppStart 全埋点点无法采集
39- this.context = getContext(this) as common.UIAbilityContext ?? binding.getApplicationContext();
36+ this.applicationContext = binding.getApplicationContext();
4037 }
4138
4239 onDetachedFromEngine(binding: FlutterPluginBinding): void {
@@ -553,9 +550,10 @@ export default class SensorsAnalyticsFlutterPlugin implements FlutterPlugin, Met
553550 return map.get(key) as T | undefined;
554551 };
555552
553+ let uiContext = getContext(this) as common.UIAbilityContext ?? this.applicationContext;
556554 // 构建 InitPara 参数
557555 const initPara: global.InitPara = {
558- context: this.context as object ,
556+ context: uiContext ,
559557 server_url: map.get('serverUrl') as string
560558 };
561559
0 commit comments