From d99ae8008ba636cf8acc063fc15b5bf1a1eff345 Mon Sep 17 00:00:00 2001 From: Cillian Myles Date: Wed, 25 Oct 2023 16:10:30 +0100 Subject: [PATCH] fix: workaround for overriding registered notification center delegate --- .../macos/Classes/FlutterLocalNotificationsPlugin.swift | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/flutter_local_notifications/macos/Classes/FlutterLocalNotificationsPlugin.swift b/flutter_local_notifications/macos/Classes/FlutterLocalNotificationsPlugin.swift index db6fbcff5..823cd3436 100644 --- a/flutter_local_notifications/macos/Classes/FlutterLocalNotificationsPlugin.swift +++ b/flutter_local_notifications/macos/Classes/FlutterLocalNotificationsPlugin.swift @@ -86,6 +86,8 @@ public class FlutterLocalNotificationsPlugin: NSObject, FlutterPlugin, UNUserNot var launchingAppFromNotification = false let presentationOptionsUserDefaults = "flutter_local_notifications_presentation_options" + static var registered = false; + // MARK: - FlutterPlugin initialization and registration init(fromChannel channel: FlutterMethodChannel) { @@ -93,6 +95,13 @@ public class FlutterLocalNotificationsPlugin: NSObject, FlutterPlugin, UNUserNot } public static func register(with registrar: FlutterPluginRegistrar) { + if (registered) { + return; + } + registered = true; + // Above is a hacky workaround to prevent attempting to register (and replacing) the notification + // center delegate multiple times. + let channel = FlutterMethodChannel(name: "dexterous.com/flutter/local_notifications", binaryMessenger: registrar.messenger) let instance = FlutterLocalNotificationsPlugin.init(fromChannel: channel) if #available(macOS 10.14, *) {