initialize static method
Initializes the SDK with the provided sdkKey
.
For more information, see the Initialize the SDK.
Implementation
static Future<MaxConfiguration?> initialize(String sdkKey) async {
if (_hasInitializeInvoked) {
// Return a future object even when the actual value is not ready.
return _initializeCompleter.future;
}
_hasInitializeInvoked = true;
_methodChannel.setMethodCallHandler(_handleNativeMethodCall);
try {
// isInitialized() returns true when Flutter is performing hot restart
bool isPlatformSDKInitialized = await isInitialized() ?? false;
if (isPlatformSDKInitialized) {
Map conf = await _methodChannel.invokeMethod('getConfiguration');
_initializeCompleter.complete(MaxConfiguration.fromJson(Map<String, dynamic>.from(conf)));
return _initializeCompleter.future;
}
var conf = await _methodChannel.invokeMethod('initialize', {
'plugin_version': _version,
'sdk_key': sdkKey,
}) as Map;
_initializeCompleter.complete(MaxConfiguration.fromJson(Map<String, dynamic>.from(conf)));
return _initializeCompleter.future;
} catch (e) {
debugPrint('Error initializing AppLovin SDK: $e');
_initializeCompleter.completeError(e);
return null;
}
}