Skip to content

Commit

Permalink
Use triggerTime to determine if alarm is ringing
Browse files Browse the repository at this point in the history
  • Loading branch information
orkun1675 committed Nov 11, 2024
1 parent 8e85a09 commit c25c4e4
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions ios/Classes/SwiftAlarmPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public class SwiftAlarmPlugin: NSObject, FlutterPlugin {
if id == nil {
result(self.isAnyAlarmRinging())
} else {
result(self.alarms[id!]?.audioPlayer?.isPlaying ?? false)
result(self.alarms[id!]?.triggerTime?.timeIntervalSinceNow ?? 1 <= 0)
}
case "setWarningNotificationOnKill":
guard let args = call.arguments as? [String: Any] else {
Expand Down Expand Up @@ -212,14 +212,14 @@ public class SwiftAlarmPlugin: NSObject, FlutterPlugin {
}

switch type {
case .began:
self.silentAudioPlayer?.play()
NSLog("[SwiftAlarmPlugin] Interruption began")
case .ended:
self.silentAudioPlayer?.play()
NSLog("[SwiftAlarmPlugin] Interruption ended")
default:
break
case .began:
self.silentAudioPlayer?.play()
NSLog("[SwiftAlarmPlugin] Interruption began")
case .ended:
self.silentAudioPlayer?.play()
NSLog("[SwiftAlarmPlugin] Interruption ended")
default:
break
}
}

Expand All @@ -237,7 +237,7 @@ public class SwiftAlarmPlugin: NSObject, FlutterPlugin {

private func isAnyAlarmRinging() -> Bool {
for (_, alarmConfig) in self.alarms {
if let audioPlayer = alarmConfig.audioPlayer, audioPlayer.isPlaying, audioPlayer.currentTime > 0 {
if alarmConfig.triggerTime?.timeIntervalSinceNow ?? 1 <= 0 {
return true
}
}
Expand Down

0 comments on commit c25c4e4

Please sign in to comment.