gdelataillade / alarm

A Flutter plugin to easily manage alarms on iOS and Android
https://pub.dev/packages/alarm
MIT License
132 stars 86 forks source link

iOS: Unable to Stop Alarm from Notification - Stop Button Not Available #262

Closed bigbossta404 closed 3 weeks ago

bigbossta404 commented 1 month ago

Alarm plugin version 4.0.6

I've encountered an issue on iOS where the stop button is not available when the alarm goes off in the notification. As a result, the alarm continues to ring indefinitely unless the app is stopped or cleared from the task manager.

Device info tested on iPhone 16 with iOS 18

gdelataillade commented 1 month ago

Hi @bigbossta404

I think I found the issue. I will fix it in the next release. I'll keep you updated.

gdelataillade commented 1 month ago

I just released version 4.0.7 with a fix. Let me know if it works !

orkun1675 commented 1 month ago

Thanks for the quick fix on this!

Re: cast issues. I've started using pigeon for Flutter <-> Native communication for my packages (e.g. native_geofence) and it has been a life saver. I don't need to copy-paste strings anymore or deal with casts.

orkun1675 commented 1 month ago

I was testing with 4.0.7 today, I'm not seeing a button in the notification, is there supposed to be one?

I also noticed that unlike Android, the notification is not dimissed once the alarm is stopped via code. Is that WAI?

Happy to help contribute code if you could give some pointers.

gdelataillade commented 1 month ago

Hi @orkun1675,

In order to have the stop button in the notification, when setting your alarm, make sure to specify a NotificationSettings .stopButton like this for example:

final alarmSettings = AlarmSettings(
      id: id,
      dateTime: selectedDateTime,
      loopAudio: loopAudio,
      vibrate: vibrate,
      volume: volume,
      assetAudioPath: assetAudio,
      warningNotificationOnKill: Platform.isIOS,
      notificationSettings: NotificationSettings(
        title: 'Alarm example',
        body: 'Your alarm ($id) is ringing',
        stopButton: 'Stop the alarm',
        icon: 'notification_icon',
      ),
    );

await Alarm.set(alarmSettings: alarmSettings);

Additionally, you need to long-press the notification for the stop button to appear. If the stopButton param is null then no stop button will be displayed. Then, about:

I also noticed that unlike Android, the notification is not dimissed once the alarm is stopped via code. Is that WAI?

This is indeed an issue I'll have to fix. I've seen the other issues you recently opened and I'll do my best to fix them as fast as possible. Please note that I am the sole developer working on this package in my free time, so it may take a few weeks to address this in the worst-case scenario. I'll keep you updated !

Lastly, if you’re interested in contributing, it would be greatly appreciated. Do you have experience with native iOS (Swift) or Android (Kotlin) development? The code is primarily handled natively to ensure alarm reliability.

orkun1675 commented 4 weeks ago

Thanks @gdelataillade it was indeed a configuration issue.

I had set stopButton to null for iOS because the docstring for the param states:

Won't work on iOS if app was killed.

I guess I was deterred since I got worried about a UX where:

  1. User kills app
  2. Somehow the alarm rings
  3. User hits stop button
  4. Alarm doesn't stop, user gets worried, doesn't know what to do
  5. They delete the app

But step (2) shouldn't happen right? So this UX flow is not likely?


Yes, I'm somewhat familiar with Swift and Kotlin. Can help pickup larger bugs that I find. To clarify, I was more so asking about the design pointers (such as guiding me to create a new class X, or update existing class Y to handle Z, etc.).

gdelataillade commented 3 weeks ago

Hi @orkun1675,

On iOS, step 2 (alarm rings) won’t trigger if the app was killed. A possible improvement could be to reopen the app when the user hits the stop button after it was killed, giving the user a feedback on their action. What do you think ? To prevent this scenario, you can also prompt users to reopen the app upon termination by using the warningNotificationOnKill parameter, which can be customized with Alarm.setWarningNotificationOnKill(title, body).


For contributing, you shouldn’t need to create new classes. Here’s an overview of the relevant files:

Services and models can be found in adjacent folders for both platforms.

Feel free to reach out if you have any questions—I’m here to help if you decide to dive into it!

Lastly, regarding your observation:

I also noticed that unlike Android, the notification is not dimissed once the alarm is stopped via code?

I’ve addressed the issue in version 4.0.8.

orkun1675 commented 3 weeks ago

I think the way the app works now, by warning the user, is great.

If the user kills the app we also should not send a notification since the alarm won't ring.


Thanks for the pointers!

gdelataillade commented 3 weeks ago

Regarding not sending an alarm notification when the app is killed, I thought it could at least serve as an indicator for the user, letting them know they received something and making them aware they missed the alarm. Showing nothing would be like nothing happened. But I understand your point of view, and I’ll think about it. By the way, I was considering an approach similar to the Alarmy app: when the app is killed, and the alarm time is reached, they send multiple notifications—one every 5 seconds or so—with sounds, simulating an alarm. It’s not a perfect solution because if the device is in Do Not Disturb or silent mode, the user may not notice.


I just released version 4.0.9 with the following features:


I believe I can close this issue now. Don’t hesitate to reopen it or create a new one if necessary. Thanks for you help !