diff --git a/ios/Classes/SwiftAlarmPlugin.swift b/ios/Classes/SwiftAlarmPlugin.swift index af6d0d77..87525c87 100644 --- a/ios/Classes/SwiftAlarmPlugin.swift +++ b/ios/Classes/SwiftAlarmPlugin.swift @@ -389,9 +389,11 @@ public class SwiftAlarmPlugin: NSObject, FlutterPlugin { } private func stopNotificationOnKillService() { - if audioPlayers.isEmpty && observerAdded { - NotificationCenter.default.removeObserver(self, name: UIApplication.willTerminateNotification, object: nil) - observerAdded = false + safeModifyResources { + if self.audioPlayers.isEmpty && self.observerAdded { + NotificationCenter.default.removeObserver(self, name: UIApplication.willTerminateNotification, object: nil) + self.observerAdded = false + } } }