android – How do we get flutter iOS data notification when the app is in terminated state

0
490


I managed to make foreground and background notifications. But I can’t get notifications when the app is in terminated screen. But only on iOS. Android is working fine.

Here is the process briefly.
I am using sending server side notifications. Android working fine at the moment. iOS not working. I use these notifications to get a video call screen(or ios call screen). My problem is I can’t get data notifications to ios when it’s in terminated state. But normal push notifications are coming.

This is the code I use for server side

 $fields = array(

                'registration_ids' => array (
                    $login_device_token->token,
            ),
            "content_available"=> true,
            "priority"=>"high",

                "notification" => array(
                    "sound"=> 'default',
                    
                ),
                    "data" => array(
                       
                        "type" => $msg_type,
                        "id" => $msg_id,
                        "sub_no" => $sub_no,
                        "name" => $name,
                        "click_action" =>'FLUTTER_NOTIFICATION_CLICK'
                    ),
                   
            );

Here is the onBackground function

 FirebaseMessaging.onBackgroundMessage((RemoteMessage message) async {
  var initialMessage = await FirebaseMessaging.instance
      .getInitialMessage()
      .then((value) async {
    await myBackgroundMessageHandler(message.data);
    await initConnect();
  });
  print(' onMessageOpenedApp  ${message.data}');
  print(' onMessageOpenedApp Notification data:::: ');
  if (!_isCameCall) {

    _isCameCall = true;
    // ---------- Get Call Notification -------------------
    if (message.data['type'] == 'call') {
      debugPrint(
          '----------- Sending trought onBackgroundMessage----------');
      await myBackgroundMessageHandler(message.data);
      await initConnect();
    }
  }
});




Future<void> _firebaseMessagingBackgroundHandler(
        RemoteMessage message) async {
      var initialMessage = await FirebaseMessaging.instance
          .getInitialMessage()
          .then((value) async {
        await myBackgroundMessageHandler(message.data);
        await initConnect();
      });
      await Firebase.initializeApp();
     ;
      if (!_isCameCall) {
        _isCameCall = true;
        // ---------- Get Call Notification -------------------
        if (message.data['type'] == 'call') {
          debugPrint('call type == call ------------');
          await myBackgroundMessageHandler(message.data);

// ---------- ANSWER AND REJECT CALL FUNCTIONS -----------------
          await initConnect();
        }
      }
    }

Me and my friend implementing this app. So do you guys have any idea to slove this issue?

I am using flutter_local_notification package and connectycube_flutter_call_kit .

I searched for a solution but nothing found. Any solution for this matter very much appreciated.