initialize method

Future<NIMResult<void>> initialize(
  1. NIMSDKOptions options
)

初始化云信 IM SDK

options 初始化配置参数。 Android 平台使用 NIMAndroidSDKOptions 类进行配置; iOS 平台使用 NIMIOSSDKOptions 类进行配置;

Implementation

Future<NIMResult<void>> initialize(NIMSDKOptions options) async {
  final startTS = DateTime.now();
  final handler = FlutterError.onError;
  FlutterError.onError = (FlutterErrorDetails details) {
    Alog.e(
      tag: tag,
      moduleName: tag,
      content:
          'flutter error detected: ${details.exceptionAsString()} \n ${details.stack}',
    );
    handler?.call(details);
  };
  Log.instance = _Alog();
  return ALogService()
      .init(config: ALoggerConfig(path: options.sdkRootDir))
      .then((value) {
    print('ALog init result: $value');
    Alog.i(
        tag: tag,
        moduleName: tag,
        content: 'print sdk info ==== '
            'operatingSystem: ${Platform.operatingSystem}, operatingSystemVersion: ${Platform.operatingSystemVersion};'
            'verCode: $_versionCode, verName: $versionName, hash: $_hash; ');
    final extras = {
      'versionCode': _versionCode,
      'versionName': versionName,
    };
    return InitializeServicePlatform.instance.initialize(options, extras);
  }).then((initResult) {
    Alog.i(
        tag: tag,
        moduleName: tag,
        content: 'initialize done ==== '
            'sdkRootDir: ${options.sdkRootDir}, '
            'success: ${initResult.isSuccess}, '
            'elapsed: ${DateTime.now().difference(startTS).inMilliseconds}');
    if (initResult.isSuccess) {
      _initialized = true;
      _sdkOptions = options;
    }
    return initResult;
  });
}