Wednesday, June 19, 2024
HomeiOS Developmentandroid - Receiving notifications in flutter app from php

android – Receiving notifications in flutter app from php


Iam sending notifications utilizing Firebase Admin SDK for PHP and receiving in Flutter app utilizing firebase and flutter_local_notification bundle.

My flutter app receiving notifications nicely in Android gadgets in foreground, background and terminated.
iOS gadgets receiving notifications solely in foreground.
Notifications presents by flutter_local_notification bundle.

The issue that app not receiving notifications in ios system when the app in background and terminated.

Drawback:
To get notifications in ios system when the app in background and terminated I must set ‘alert’ => $knowledge, then the app receiving notifications, BUT notifications sends on to the system to not the app by way of flutter_local_notification.

I wish to current notifications in all modes and gadgets by way of flutter_local_notification.

Is there any factor which disable notifications receiving in ios system when the app in background and terminate? Tips on how to clear up it?

Flutter: 3.22.2

firebase_core: ^3.1.0
firebase_messaging: ^15.0.1
firebase_database: ^11.0.1
flutter_local_notifications: ^17.1.2

PHP

    $knowledge = [
            'title' => $title,
            'body' => $description,
            'id' => $id,
        ];

                    $message = CloudMessage::withTarget('token', $person['firebase_token'])
                        //  ->withNotification(Notification::create($title, $description))
                        ->withData($knowledge);

                    if(strtolower($person['platform']) == 'android'){
                        // Instance from https://firebase.google.com/docs/cloud-messaging/admin/send-messages#android_specific_fields
                        $config = AndroidConfig::fromArray([
                            'ttl' => '3600s',
                            'priority' => 'normal',
                            'data' => [
                                'title' => $title,
                                'body' => $description,
                                'icon' => 'stock_ticker_update',
                                'color' => '#f45342',
                                'sound' => 'default',
                            ],
                        ]);

                        $message = $message->withAndroidConfig($config);
                    }
                    else if(strtolower($person['platform']) == 'ios'){
                        $config = ApnsConfig::fromArray([
                            'headers' => [
                                'apns-priority' => '5',
                                "apns-push-type" => "background",
                              "apns-topic" => "io.flutter.plugins.firebase.messaging", // bundle identifier

                            ],
                            'payload' => [
                                'aps' => [
                                    'contentAvailable'=> true,
                                //  'alert' => $data,
                                    'badge' => 1,
                                    'sound' => 'default',
                                  "mutable-content" => 1,
                                ],
                                'knowledge' => $knowledge,
                            ],
                        ]);

                        $message = $message->withApnsConfig($config);
                    }


                    attempt {
                        $messaging->ship($message);
                    } catch (Exception $e) {
                        echo "Error sending message: " . $e->getMessage();
                    }

AppDelegate.swift

import UIKit
import Flutter
import flutter_local_notifications

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
  override func utility(
    _ utility: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
  ) -> Bool {

       FlutterLocalNotificationsPlugin.setPluginRegistrantCallback { (registry) in
           GeneratedPluginRegistrant.register(with: registry)
       }

  if #obtainable(iOS 10.0, *) { 
     UNUserNotificationCenter.present().delegate = self as? UNUserNotificationCenterDelegate
   }
     GeneratedPluginRegistrant.register(with: self)
     return tremendous.utility(utility, didFinishLaunchingWithOptions: launchOptions)
   }
}



Supply hyperlink

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments