initialize method
Future<bool>
initialize({
- required PushTokenHandler onFcmTokenHandle,
- required FcmSilentDataHandler onFcmSilentDataHandle,
- List<
String> ? licenseKeys, - PushTokenHandler? onNativeTokenHandle,
- bool debug = false,
INITIALIZING METHODS *********************************************
Initializes the plugin, setting the onFcmTokenHandle
and onFcmSilentDataHandle
listeners to capture Firebase Messaging events and the licenseKeys
necessary
to validate the release use of this plugin.
You should call this method only once at main_complete.dart.
debug
: enables the console log prints
Implementation
/// Initializes the plugin, setting the [onFcmTokenHandle] and [onFcmSilentDataHandle]
/// listeners to capture Firebase Messaging events and the [licenseKeys] necessary
/// to validate the release use of this plugin.
/// You should call this method only once at main_complete.dart.
/// [debug]: enables the console log prints
Future<bool> initialize(
{required PushTokenHandler onFcmTokenHandle,
required FcmSilentDataHandler onFcmSilentDataHandle,
List<String>? licenseKeys,
PushTokenHandler? onNativeTokenHandle,
bool debug = false}) async {
WidgetsFlutterBinding.ensureInitialized();
_tokenFcmHandler = onFcmTokenHandle;
_tokenNativeHandler = onNativeTokenHandle;
final dartCallbackReference =
PluginUtilities.getCallbackHandle(silentPushBackgroundMain);
final tokenCallbackReference =
PluginUtilities.getCallbackHandle(onFcmTokenHandle);
final silentCallbackReference =
PluginUtilities.getCallbackHandle(onFcmSilentDataHandle);
_channel.setMethodCallHandler(_handleMethod);
_isInitialized =
await _channel.invokeMethod(CHANNEL_METHOD_FCM_INITIALIZE, {
DEBUG_MODE: debug,
LICENSE_KEYS: licenseKeys,
DART_BG_HANDLE: dartCallbackReference!.toRawHandle(),
TOKEN_HANDLE: tokenCallbackReference?.toRawHandle(),
SILENT_HANDLE: silentCallbackReference?.toRawHandle()
});
if (tokenCallbackReference == null) {
print('Callback FcmTokenHandler is not defined or is invalid.'
'\nPlease, ensure to create a valid global static method to handle it.');
}
if (silentCallbackReference == null) {
print('Callback FcmSilentDataHandler is not defined or is invalid.'
'\nPlease, ensure to create a valid global static method to handle it.');
}
return _isInitialized;
}