iOS Development

swift – Push notification not engaged on iOS Flutter

Spread the love

Can not seem to figure-out show notifications on iOS, however works tremendous on Android.

  • Utilizing flutter_local_notification package deal
  • I’m utilizing a bodily system
  • Added the required code to appdelegate.swift

right here is my code for the cloud operate:

// Fetch the primary title of the consumer who created the appointment
const creatorSnapshot = await admin
const creator = creatorSnapshot.knowledge();
const creatorName = creator ? creator.first_name : "Somebody";
const requestedUserId = appointment.createdBy;

// Get all customers to ship notification to, excluding the creator
const usersSnapshot = await admin.firestore().assortment("customers").get();
const tokens = [];
usersSnapshot.forEach((doc) => {
  if ( !== appointment.createdBy) {
    const userToken = doc.knowledge().fcmToken;
    if (userToken) {

if (tokens.size === 0) {
  console.log("No legitimate tokens discovered. Notification not despatched.");
  return null;

// Setting up the FCM message
const message = {
  notification: {
    title: "New Session Out there",
    physique: `${creatorName} has created an appointment for ${ part of(
      ", "
    )} at ${appointment.date_time
      .toLocaleString()}, are you accessible?`,
  knowledge: {
    sort: "new_appointment",
    appointmentId: appointmentId,
    requestedUserId: requestedUserId,
  tokens: tokens,

// Sending the FCM message
return admin
  .then((response) => {
    console.log(response.successCount + " messages had been despatched efficiently");

And right here is my code for dealing with the notifications

// iOS Initialization
var initializationSettingsIOS = DarwinInitializationSettings(
  requestAlertPermission: true,
  requestBadgePermission: true,
  requestSoundPermission: true,
  onDidReceiveLocalNotification: onDidReceiveLocalNotification,

// request permissions
//for ios
if (Platform.isIOS) {
  await flutterLocalNotificationsPlugin
        alert: true,
        badge: true,
        sound: true,
  //for android
} else if (Platform.isAndroid) {
  remaining AndroidFlutterLocalNotificationsPlugin? androidImplementation =

  // ignore: unused_local_variable
  remaining bool? grantedNotificationPermission =
      await androidImplementation?.requestNotificationsPermission();

// InitializationSettings for each platforms
var initializationSettings = InitializationSettings(
    android: initializationSettingsAndroid, iOS: initializationSettingsIOS);

print('step 1');

// initialize the plugins
await flutterLocalNotificationsPlugin.initialize(
      (NotificationResponse notificationResponse) {
    if (notificationResponse.notificationResponseType ==
        NotificationResponseType.selectedNotification) {


FirebaseMessaging.onMessage.hear((RemoteMessage message) {
  print('step 2');

FirebaseMessaging.onMessageOpenedApp.hear((RemoteMessage message) {

// Android Notification Particulars
var androidDetails = const AndroidNotificationDetails(
  'Appointment Notifications',
  channelDescription: 'Get notified about new appointments and updates',
  significance: Significance.max,

// iOS Notification Particulars
var iosDetails = const DarwinNotificationDetails(
    presentAlert: true, presentSound: true, subtitle: 'Notification');

var notificationDetails =
    NotificationDetails(android: androidDetails, iOS: iosDetails);

String payload = json.encode(message.knowledge);

// Show the notification utilizing the flutterLocalNotificationsPlugin
await flutterLocalNotificationsPlugin.present(
  message.notification?.title ?? 'Default Title',
  message.notification?.physique ?? 'Default physique',
  payload: payload,

Right here is my data.plist:


Tried all of the information discovered on-line and nonetheless cant get notification to work on iOS

Leave a Reply

Your email address will not be published. Required fields are marked *