init method

dynamic init({
  1. AppRunner? appRunner,
})

Implementation

init({AppRunner? appRunner}) {
  if (_umengApmInited) {
    warnLog('SDK 重复实例化,停止逻辑执行');
    return;
  }
  runZonedGuarded(() {
    nativeTryCatch(handler: () async {
      if (initFlutterBinding != null) {
        initFlutterBinding!();
      } else {
        ApmWidgetsFlutterBinding.ensureInitialized();
      }

      if (appRunner != null) {
        ApmNavigatorObserver singleInstance = getApmNavigatorObserver();
        final Widget rootWidget = await appRunner(singleInstance);
        runApp(rootWidget);
      }
      try {
        final String? nativeSdkVersion =
            await ApmMethodChannel.getNativeSdkVersion();
        if (nativeSdkVersion != null) {
          if (Platform.isAndroid) {
            printLog('SDK检查:当前Android APM SDK版本为 $nativeSdkVersion');
            printLog(
                '提示:Android APM SDK 需在v1.9.3及以上版本才能支持Flutter监测 请自行检查 !!!!!');
          }
          if (Platform.isIOS) {
            printLog('SDK检查:当前iOS APM SDK版本为 $nativeSdkVersion');
            printLog('提示:iOS APM SDK 需在v1.8.4及以上版本才能支持Flutter监测 请自行检查 !!!!!');
          }
        }
      } catch (e) {}

      bool waitResult = await waitNativeSdkInited();
      if (waitResult) {
        callInitOptios();
      } else {
        printLog('=======================================');
        printLog('===== 等待接收APM Native SDK 初始化结束状态 =====');
        printLog(
            '===== 如等待超过5s 可参考【SDK常见集成问题】https://developer.umeng.com/docs/193624/detail/2536504 =====');
        printLog('=======================================');
        Timer.periodic(Duration(milliseconds: 1000), (Timer t) async {
          bool inited = await waitNativeSdkInited();
          if (inited) {
            printLog('=======================================');
            printLog('===== 成功接收APM Native SDK 初始化状态 =====');
            printLog('=======================================');
            callInitOptios();
            t.cancel();
          }
        });
      }
    });
  }, (exception, stack) {
    if (exception is ApmFlutterError) {
      final Map<String, dynamic> errorDetail = exception.errorDetail;
      ExceptionTrace.handleApmSdkException(
          errorDetail['exception'], errorDetail['stackTrace'] ?? '');
    } else {
      ExceptionTrace.zonedGuardedErrorHandler(
          exception: exception, stack: stack);
    }
    if (onError != null) {
      onError!(exception, stack);
    }
  });

  _umengApmInited = true;
}