Open moosalim opened 1 year ago
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.
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.
I agree with you @meliksahcakirr, it would make more sense.
@moosalim what do you think ?
@gdelataillade I agree, this is good idea, @meliksahcakirr thanks for the suggestion
Awesome. I'll close the issue then. Don't hesitate to open another one if you have any other question.
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
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.
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.
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
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.
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..
Can someone show me the code on how to allow users to repeat alarms daily?
Hey the package is good for some things but there are a few things that should be in the package.
or could you suggest any other way of doing it in flutter with the current package status
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.
Hi @gdelataillade would you happen to have pseudocode to show this in the example file?
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.
@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.
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.
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
Hi @deep526, what kind of errors do you have ?
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
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,
);
}
}
}
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.
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?
@steveng15 You should put it in a class like AlarmController
, import the class and then call AlarmController.setPeriodicAlarms
.
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
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.
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.
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
@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.
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.
@gdelataillade If I want to set an alarm for 9:00 a.m. every Friday, how many alarms should I set? Thanks a lot.
@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.
@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); }); }
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 ?