Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make alarm periodic #47

Open
moosalim opened this issue May 9, 2023 · 36 comments
Open

Make alarm periodic #47

moosalim opened this issue May 9, 2023 · 36 comments
Assignees
Labels
enhancement New feature or request technical limitation The issue can't be fixed due to technical limitations

Comments

@moosalim
Copy link

moosalim commented May 9, 2023

Hello

Thanks for the plugin, appreciate your effort. The alarm is not periodic, it just ring one time. Whereas I believe it should ring every day on the same time, e.g morning wakup every day. Is this a bug or a feature to be added ?

@moosalim moosalim added the bug Something isn't working label May 9, 2023
@gdelataillade
Copy link
Owner

Hi! Thanks for your interest in the package.

Yes, this is a feature that could be added. I'll add it when I find the time to do it. I'll let you know.

@meliksahcakirr
Copy link

I don't think it should be the libraries responsibility. Normally, when get a callback on in our app regarding our alarm went off, we can register the new one again.

@gdelataillade
Copy link
Owner

I agree with you @meliksahcakirr, it would make more sense.

@moosalim what do you think ?

@gdelataillade gdelataillade added the needs author feedback Further information or answer is requested by author label May 13, 2023
@moosalim
Copy link
Author

@gdelataillade I agree, this is good idea, @meliksahcakirr thanks for the suggestion

@gdelataillade
Copy link
Owner

Awesome. I'll close the issue then. Don't hesitate to open another one if you have any other question.

@azmasamy
Copy link

Can't agree with the conclusion you guys reached for this feature. What if the user didn't open the app when the alarm went off?
I need to schedule a daily alarm that fires even if the user didn't open the app after the first scheduled alarm

@gdelataillade gdelataillade added enhancement New feature or request and removed needs author feedback Further information or answer is requested by author bug Something isn't working labels May 26, 2023
@gdelataillade gdelataillade reopened this May 26, 2023
@gdelataillade
Copy link
Owner

I see. I can make the Android alarm periodic but for the iOS part I don't know if there is a way to execute native code in the background periodically.

I'll take a close look at it when I find some time. Feel free to help if you want.

@gdelataillade gdelataillade changed the title The Alarm rings one time only, and disappear from the list Make alarm periodic Nov 21, 2023
@gdelataillade gdelataillade added the technical limitation The issue can't be fixed due to technical limitations label Nov 21, 2023
@gdelataillade
Copy link
Owner

In summary, while periodic alarms can be implemented on Android, this is not feasible for iOS. To maintain consistency between both platforms, I will not be adding this feature to the package (except if I found a solution). As an alternative, you could store the scheduled days for alarms and reset them for the upcoming week each time the app is launched.

@gbbest15
Copy link

gbbest15 commented Nov 21, 2023

In summary, while periodic alarms can be implemented on Android, this is not feasible for iOS. To maintain consistency between both platforms, I will not be adding this feature to the package (except if I found a solution). As an alternative, you could store the scheduled days for alarms and reset them for the upcoming week each time the app is launched.

i think there should be a work around for iOS or what is the problem why is not feasible on iOS if i may ask..
what of if we use background fetch

@gdelataillade
Copy link
Owner

Hi @gbbest15

Thank you for your question. Indeed, I am already using background fetch in the application, but the issue lies in the fact that iOS does not provide an API to automatically repeat alarms. This would mean that I would have to manually set alarms for every Monday, for instance, but for what duration? The entire year? That seems impractical.

Additionally, it's important to note that the longer a task remains active in background fetch, the higher the chance that iOS will terminate it. Therefore, it’s better to regularly reschedule these tasks to ensure they function properly.

If you have any ideas on how to circumvent this limitation or improve this functionality, I would be delighted to hear them. Also, feel free to ask any other questions you might have.

@gbbest15
Copy link

gbbest15 commented Nov 21, 2023

Hi @gbbest15

Thank you for your question. Indeed, I am already using background fetch in the application, but the issue lies in the fact that iOS does not provide an API to automatically repeat alarms. This would mean that I would have to manually set alarms for every Monday, for instance, but for what duration? The entire year? That seems impractical.

Additionally, it's important to note that the longer a task remains active in background fetch, the higher the chance that iOS will terminate it. Therefore, it’s better to regularly reschedule these tasks to ensure they function properly.

If you have any ideas on how to circumvent this limitation or improve this functionality, I would be delighted to hear them. Also, feel free to ask any other questions you might have.

okay, now i think i understand, i will also make some research here if i can get somethings... but right now is to trigger it with my backend base on my thinking now.. i will see make research on this..

@deep526
Copy link

deep526 commented Jan 13, 2024

Can someone show me the code on how to allow users to repeat alarms daily?

@vinayakgupta29
Copy link

vinayakgupta29 commented Feb 24, 2024

Hey the package is good for some things but there are a few things that should be in the package.

  • repeat alarm either daily and/or on selected day.

or could you suggest any other way of doing it in flutter with the current package status

@gdelataillade
Copy link
Owner

Hi @vinayakgupta29 @deep526

Making alarms periodical in the plugin with the workaround is not the priority at the moment. If you need to make alarms periodical, the workaround to add to your app is:

Every time the user opens the app, you need to schedule his alarms for the following 7 days.

Let me know if you have any question.

@deep526
Copy link

deep526 commented Mar 3, 2024

Hi @gdelataillade would you happen to have pseudocode to show this in the example file?

@gdelataillade
Copy link
Owner

Hi @deep526

I will write a Github Gist with an example of a periodic alarm implementation when I have some time. I'll keep you updated here.

@deep526
Copy link

deep526 commented Mar 7, 2024

@gdelataillade Yes please that would be amazing. I got custom sounds made for alarms and created the alarm, but my users are complaining they can't repeat the alarm and it's also not stoping when users click the notification.

@gdelataillade
Copy link
Owner

Hi @deep526

I will write a Github Gist with an example of a periodic alarm implementation when I have some time. I'll keep you updated here.

Hi everyone,

Here's a Github Gist I wrote to give you an idea of how to implement periodic alarms in your app:

https://gist.github.com/gdelataillade/3dae217917d417c5f367557489133619

Please don't hesitate if you have any question.

@deep526
Copy link

deep526 commented Mar 17, 2024

hi @gdelataillade thank you for providing the code for periodic alarms. Unfortunately I'm not an expert in flutter so I was unable to implement this into my code. I tried modifying the edit_alarm.dart file and created the ui to show days of the week selected but it was giving errors, it's requiring me to change code on the package files. Hopefully you'll have this option implemented in the example file so it's easier for us self taught coders to implement lol. Thanks for your help, I'll just remove the alarm feature and continue working on trying to make it periodic for now

@gdelataillade
Copy link
Owner

Hi @deep526, what kind of errors do you have ?

@deep526
Copy link

deep526 commented Mar 18, 2024

Hi @gdelataillade, there no error message that shows up however, when alarm rings and user is directed to the ring.dart screen and they press stop. Then the alarm is deleted. I believe you said the alarm needs to rebuild every time the app opens up or something. I'm just not sure how the implementation works.

This is the code I used to allow users input for repeating:

Future setPeriodicAlarms(TimeOfDay time, List selectedDays) async {
final nbDays = 7;

final now = DateTime.now();

for (var i = 0; i < nbDays; i++) {
  final dateTime = DateTime(
    now.year,
    now.month,
    now.day,
    time.hour,
    time.minute,
  ).add(Duration(days: i));

  if (selectedDays.contains(dateTime.weekday)) {
    final alarmSettings = AlarmSettings(
      id: dateTime.day,
      dateTime: dateTime,
      assetAudioPath: 'assets/',
      notificationTitle: 'Alarm ringing!',
      notificationBody: 'Periodic alarm ringing, day ${dateTime.day}.',
    );
    await Alarm.set(
      alarmSettings: alarmSettings,
    );
  }
}

}

@gdelataillade
Copy link
Owner

Hi @deep526

Make sure to call Alarm.init before executing this function. Please carefully read the Readme if it's not already done. Let me know if you still have issues.

@steveng15
Copy link

Hi @deep526

Make sure to call Alarm.init before executing this function. Please carefully read the Readme if it's not already done. Let me know if you still have issues.

I saved Alarm.init in main.dart and the function for alarm repetition is in another file. how to call it?

@gdelataillade
Copy link
Owner

@steveng15 You should put it in a class like AlarmController, import the class and then call AlarmController.setPeriodicAlarms.

@arymuhammad
Copy link

hello, mr
i wanna ask, why my alarm always delete when i run this function Alarm.stop(id),
i just want to stop my alarm, not delete it

please help me.
thanks alot

@gdelataillade
Copy link
Owner

Hi @arymuhammad

As explained in this issue, it's not possible to set a periodical alarm at the moment, so you have to do it manually. Please read the issue for more information.

@a-3isa
Copy link

a-3isa commented May 26, 2024

there is a solution to make the alarm periodic. you can make the stop button stop the current alarm and start a new alarm after 24 hours, and make another button which kill the alarm.

@deep526
Copy link

deep526 commented May 27, 2024

Yes, I created a separate button and labeled it "Repeat Tomorrow" to allow users to repeat the alarm at the exact same time next day. It just sets a new alarm 24hrs in the future

@devnta
Copy link

devnta commented May 31, 2024

@gdelataillade
Thanks for your support.
What happens if the user doesn't launch the app?
How do I schedule in this case?
p/s: Sorry for my bad English.

@gdelataillade
Copy link
Owner

Hi @phamquoctrongnta

It is recommended that users launch the app to ensure future alarms are scheduled and active. This serves as a security measure to confirm that alarms are functioning correctly. Additionally, it’s advisable to schedule not only your next alarm but also subsequent ones, especially for periodic alarms.

Hope this helps, let me know if you have any questions.

@devnta
Copy link

devnta commented Jun 4, 2024

@gdelataillade
If I want to set an alarm for 9:00 a.m. every Friday, how many alarms should I set?
Thanks a lot.

@gdelataillade
Copy link
Owner

@phamquoctrongnta honestly I don't know, I would try to have alarms scheduled for the next 2 Fridays and see how it goes. Don't hesitate to share your feedback, it can be valuable for everyone.

@a-3isa
Copy link

a-3isa commented Jun 7, 2024

@gdelataillade If I want to set an alarm for 9:00 a.m. every Friday, how many alarms should I set? Thanks a lot.

modify the stopAlarm function like this

void stopAlarm(AlarmSettings alarmSettings) { DateTime newdDateTime = alarmSettings.dateTime.add(const Duration(days: 7)); final newalarmSettings = AlarmSettings( id: alarmSettings.id, dateTime: newdDateTime, loopAudio: alarmSettings.loopAudio, vibrate: alarmSettings.vibrate, volume: alarmSettings.volume, assetAudioPath: alarmSettings.assetAudioPath, notificationTitle: alarmSettings.notificationTitle, notificationBody: alarmSettings.notificationBody, enableNotificationOnKill: alarmSettings.enableNotificationOnKill, ); Alarm.stop(alarmSettings.id).then((bool result) { return Alarm.set(alarmSettings: newalarmSettings); }); }

@khaledmurtaja
Copy link

khaledmurtaja commented Dec 4, 2024

is there any updates on this @gdelataillade ?

@gdelataillade
Copy link
Owner

@khaledmurtaja sorry I currently don’t have plans to implement this feature, primarily because it would be Android-only. However, contributions are always welcome if you’d like to work on it.

In the meantime, I’ve shared a GitHub Gist that might help you implement periodic alarms in your app:

https://gist.github.com/gdelataillade/3dae217917d417c5f367557489133619

Please note that the code in the Gist is outdated, but the underlying idea should still be useful as a starting point. Let me know if you have any questions!

@singhcreations
Copy link

its not workable at all when we select the alarm at first time then alarm works well when we use this code then it will not workable idk what is the issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request technical limitation The issue can't be fixed due to technical limitations
Projects
None yet
Development

No branches or pull requests