0

I need to run a task at a specific time (for example 2 hours later) in Flutter, something like an alarm, I have searched in flutter and I know that this is not possible easily.

I have tested work manager and it didn't work properly. I have done the Android Part of the project with Platform_channel and Android Alarm Manager.

I was wondering If you know any other ways in IOS (or Flutter if possible).


  • some similar questions were asked before but they are too old (this page and this page) and haven't had any new solution or update since 2014.
  • I need to run some code so as far as I know local notification its not the Answer.

EDIT:

My App needs to play a sound (1~3 minutes length) at specific time something like an alarm.

Sajjad
  • 2,593
  • 16
  • 26
  • 4
    You can't. There is no way to execute code at a specific time on iOS. – Paulw11 Jan 16 '23 at 11:51
  • 1
    Most things aren't possible. your best bet would be to use Background Tasks https://developer.apple.com/documentation/backgroundtasks – sebbelebbe Jan 16 '23 at 12:11
  • 1
    You will need to use a push notification, sent from a server. There are limitations with that, but generally that will work for your use case. The answers you linked are all up-to-date. It has never been possible to run arbitrary code at an arbitrary time on iOS. This is by design, and you should not expect it to ever be possible. You must use a push notification or you must redesign your app not to need this. If you explain what code the user wants your app to run, we may be able to help you design that. – Rob Napier Jan 25 '23 at 20:04

1 Answers1

1

I would check out this question and answer Local notification sound not playing while app in background - Swift. It's not exactly the same as your question but I think you could use the same technique with a little creativity.

Eric
  • 569
  • 4
  • 21
  • 1
    Thank you so much for your answer, the best answer that I seen. thanks again. – Sajjad Jan 26 '23 at 07:18
  • did you successfully release your app in App Store? without any opposition from apple? – Sajjad Jan 26 '23 at 07:40
  • Yep check it out - its called Quik Alarm. However, I have encountered a very rare and strange bug where the notification pops up but the sound does not play, and I have yet to figure out the reason. I'm not sure if it's due to the strategy mentioned or something else in my code, but I thought I'd mention it just in case. It happens maybe once in 100+ times. – Eric Jan 27 '23 at 15:03