AlarmKit Fixed Schedule Going off at Midnight

I am getting bug reports from users that occasionally the AlarmKit alarms scheduled by my app are going off exactly at midnight.

In my app, users can set recurring alarms for sunrise/sunset etc. I implement this as fixed schedule alarms over the next 2-3 days with correct dates pre-computed at schedule time. I have a background task which is scheduled to run at noon every day to update the alarms for the next 2-3 days.

Are there any limitations to the fixed schedule which might be causing this unintended behavior of going off at midnight?

Answered by ekurutepe in 886110022

In my case, I was able to resolve this by making sure my app was not cancelling and scheduling too many alarms at every update. Assigning stable id's and then diffing the current set of alarms to the desired set of alarms and only performing the required operations fixed the issue. When this issue was happening at every update, I was cancelling all scheduled alarms and replacing them with new alarms. I was never able to log any errors but after these changes this problem went away.

Hi, I’m experiencing the same issue with AlarmKit alarms occasionally firing at midnight. It seems I’m not the only one. I also created a post describing the same problem here:

Would appreciate if Apple could take a look at this behavior.

Same here! Many users are complaining about that. I spent a huge amount of time refactoring and testing but could never emulate it.

Accepted Answer

In my case, I was able to resolve this by making sure my app was not cancelling and scheduling too many alarms at every update. Assigning stable id's and then diffing the current set of alarms to the desired set of alarms and only performing the required operations fixed the issue. When this issue was happening at every update, I was cancelling all scheduled alarms and replacing them with new alarms. I was never able to log any errors but after these changes this problem went away.

@ekurutepe Dang, I'm doing exactly what you were doing. I'll try your new approach. Thanks.

@ekurutepe did you file any bug when that happened and provided the sysdiagnose to see the schedule? Thanks

Albert
  Worldwide Developer Relations.

AlarmKit Fixed Schedule Going off at Midnight
 
 
Q