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(Duration(milliseconds: 100));
  }
  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;
      return true;
    }
  }
  return false;
}