init method

  1. @override
Future<bool> init(
  1. dynamic backgroundMessageHandler(
    1. Map
    ), [
  2. String title = "Pushed",
  3. String body = "The service active"
])
override

Implementation

@override
Future<bool> init(Function(Map<dynamic, dynamic>) backgroundMessageHandler,
    [String title = "Pushed", String body = "The service active"]) async {
  apnsToken = null;
  messageCallback = backgroundMessageHandler;
  methodChannel.setMethodCallHandler(_handle);

  await methodChannel.invokeMethod('configure');
  await requestNotificationPermissions();
  for (var counter = 0; counter < 30; counter++) {
    if (apnsToken != null) break;
    await Future.delayed(const Duration(milliseconds: 100));
  }
  await methodChannel
      .invokeMethod<bool>('setLog', {"event": "FL ApnsToken: $apnsToken"});
  if (apnsToken != null) {
    var token = await methodChannel.invokeMethod<String>('getToken');
    var newToken = await getNewToken(token ?? "", apnsToken: apnsToken);

    if (token != newToken && newToken != "") {
      token = newToken;
      await methodChannel.invokeMethod<bool>('setToken', {"token": token});
    }
    if (token != "") {
      FlutterPushedMessagingPlatform.pushToken = token;
      FlutterPushedMessagingPlatform.status = ServiceStatus.active;
      await methodChannel
          .invokeMethod<bool>('setLog', {"event": "FL Init Success"});
      return true;
    }
  }
  await methodChannel.invokeMethod<bool>('setLog', {"event": "FL Init Fail"});
  return false;
}