skip to Main Content

I have flutter app. It is working for iOS. now I try to run it on macos – I have problems:

  1. I added GoogleService-Info.plist to my macos/runner

  2. my app uses firebase_messaging(for push notification)

    final settings = await FirebaseMessaging.instance.requestPermission(
    announcement: true,
    carPlay: true,
    sound: true,
    criticalAlert: true,
    );
    

this code returns an error:

 [firebase_messaging/unknown] Notifications are not allowed for this application

Found this discussion

here they advise you to manually add permissions for your application, via System Preferences > Notifications

but I don’t see my app there. i installed it via TestFlight – but that didn’t help either, the app is not listed.

how do i solve this problem? any advice – I will be grateful

also i don’t know how to configure my app properly. I found this document but there are no details (what permissions are needed and other details)

2

Answers


  1. Firebase Messaging currently does not support macOS.

    To implement push notifications for macOS, you must use the Apple Push Notification service directly. However, you are to write platform-specific code for macOS.

    Login or Signup to reply.
  2. Firebase Messaging currently does not support macOS. The plugin is designed for Android and iOS platforms only. This is the reason you’re encountering an error when trying to run your Flutter app on macOS.

    However, you can still implement native macOS notifications by using a different package. One of the options is to use the flutter_local_notifications package.

    1. First, add the flutter_local_notifications package to your pubspec.yaml file:
    dependencies:
      flutter_local_notifications: ^8.2.0
    
    
    1. Import the package in the file where you want to use notifications:
    import 'package:flutter_local_notifications/flutter_local_notifications.dart';
    
    1. Initialize the local notifications plugin:
    final FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin();
    
    1. Configure local notifications:
    void configureLocalNotifications(BuildContext context) {
      const initializationSettingsAndroid = AndroidInitializationSettings('ic_launcher');
      final InitializationSettings initializationSettings = InitializationSettings(android: initializationSettingsAndroid);
      flutterLocalNotificationsPlugin.initialize(initializationSettings);
    }
    
    1. Display a notification:
    void displayNotification(String title, String body) async {
      const androidPlatformChannelSpecifics = AndroidNotificationDetails(
          'your_channel_id', 'your_channel_name', 'your_channel_description',
          importance: Importance.max, priority: Priority.high, showWhen: false);
      const platformChannelSpecifics = NotificationDetails(android: androidPlatformChannelSpecifics);
      await flutterLocalNotificationsPlugin.show(0, title, body, platformChannelSpecifics, payload: 'item');
    }
    

    You can call the displayNotification function when you want to display a local notification on your macOS app.

    Keep in mind that this solution is for local notifications and will not work with Firebase push notifications. If you need a cross-platform solution for push notifications, you may need to explore third-party services like OneSignal or Pusher Beams, which provide support for macOS.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search