initWithConfig static method
Initialize the SDK This should only be called once returns the error or success message
Implementation
static Future<String?> initWithConfig(CountlyConfig config) async {
if (config.loggingEnabled != null) {
_isDebug = config.loggingEnabled!;
}
log('Calling "initWithConfig"');
if (_instance._countlyState.isInitialized) {
String msg = 'initWithConfig, SDK is already initialized';
log(msg, logLevel: LogLevel.ERROR);
return msg;
}
if (config.serverURL.isEmpty) {
String msg = 'initWithConfig, serverURL cannot be empty';
log(msg, logLevel: LogLevel.ERROR);
return msg;
}
if (config.appKey.isEmpty) {
String msg = 'initWithConfig, appKey cannot be empty';
log(msg, logLevel: LogLevel.ERROR);
return msg;
}
if (config.manualSessionEnabled != null) {
_manualSessionControlEnabled = config.manualSessionEnabled!;
if (config.manualSessionEnabled!) {
_instance._sessionsInternal.enableManualSession();
}
}
if (config.enableUnhandledCrashReporting != null) {
_enableCrashReportingFlag = config.enableUnhandledCrashReporting!;
}
_channel.setMethodCallHandler(_methodCallHandler);
List<dynamic> args = [];
args.add(_configToJson(config));
final String? result = await _channel.invokeMethod('init', <String, dynamic>{'data': json.encode(args)});
_instance._countlyState.isInitialized = true;
if (config.remoteConfigGlobalCallbacks.isNotEmpty) {
log('[initWithConfig] About to register ${config.remoteConfigGlobalCallbacks.length} callbacks', logLevel: LogLevel.VERBOSE);
}
for (final callback in config.remoteConfigGlobalCallbacks) {
Countly.instance._remoteConfigInternal.registerDownloadCallback(callback);
}
return result;
}