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: putting app to background and foreground again, the alarm will play even if it is not due yet #116

Closed vsaase closed 11 months ago

vsaase commented 11 months ago

Alarm plugin version ex: 2.1.1

Describe the bug

To Reproduce Steps to reproduce the behavior:

  1. I start the alarm timer like this:
    final startTime = DateTime.now().toUtc();
    final alarmId = Random().nextInt(100000);
    final duration = Duration(minutes:1);
    final alarmSettings = AlarmSettings(
    id: alarmId,
    dateTime: startTime.add(duration),
    assetAudioPath: 'assets/alarm.mp3',
    loopAudio: true,
    vibrate: true,
    volumeMax: true,
    notificationTitle: 'Alarm',
    notificationBody: event.context,
    enableNotificationOnKill: true,
    stopOnNotificationOpen: true);
    await Alarm.set(alarmSettings: alarmSettings);
  2. I put the app to background
  3. I put the app to foreground
  4. I hear the alarm sound at the device sound level (not as loud as when the alarm is due, i.e. volumeMax)
  5. stopping the alarm with Alarm.stop also stops the playback

Expected behavior nothing happens

Device info Provide device info (Manufacturer, OS version, ...) Ex: iPhone 13 Pro Max, iOS 17.1.2.

gdelataillade commented 11 months ago

Hi @vsaase

Thanks for sharing your issue.

Are you sure the alarm is scheduled at the right time ? Can you share your logs please ? It might help.

vsaase commented 11 months ago

with final startTime = DateTime.now().toUtc();:

flutter: [Alarm] Notification with id 52262 scheduled successfuly at 2023-12-03 21:16:52.661837Z GMT
flutter: [Alarm] Alarm with id 52262 scheduled successfully at 2023-12-03 21:16:52.661837Z
flutter: [Alarm] Notification with id 52262 canceled
flutter: [Alarm] Alarm with id 52262 stopped with success

with final startTime = DateTime.now();:

flutter: [Alarm] Notification with id 31764 scheduled successfuly at 2023-12-03 21:21:06.689915Z GMT
flutter: [Alarm] Alarm with id 31764 scheduled successfully at 2023-12-03 22:21:06.689915
flutter: [Alarm] Notification with id 31764 canceled
flutter: [Alarm] Alarm with id 31764 stopped with success

These are the right times, in both cases I get the alarm sound on resuming the app. Even adding a day or removing a day from the starttime leads to the same issue, so I guess it is not because of timing. I am on flutter beta.

vsaase commented 11 months ago

When the app is in background and the alarm goes of I also do not hear the alarm sound, I just see the notification and feel the vibration.

gdelataillade commented 11 months ago

Ok that's really weird. Did you follow the plugin's iOS installation steps ? https://github.com/gdelataillade/alarm/blob/feat/ios-background-fetch/help/INSTALL-IOS.md

I'm about to release version 3.0.0, hope that will fix your issue. You can try it now using version 3.0.0-dev.5 if you want.

vsaase commented 11 months ago

that's embarrassing, I did not follow the installation steps. I think I was in a hurry and did not realize that I have to follow the link to the steps in your README, maybe you could make that even more obvious..

sorry for taking your time, and thanks, it works perfectly now

gdelataillade commented 11 months ago

No problem. I'm glad it works now.