Is this a good approach for creating this Apple Watch sleep game feature?

I am creating a watch app that keeps track of the amount of time a user has been asleep for and then updates a game using an API in real time if they surpass another user's sleep time. They select who they want to surpass so the app knows the target time they want to sleep for. I know this probably sounds silly, it's not the final iteration of what I want to build but I know I will need this functionality.

So I need this watch app to be able to update the game if they surpass the opponent while the user is sleeping. I don't think this is possible without using extended runtime sessions so that it can run in the background and check to see how long the user has been asleep for after the watch locks.

As far as I know the extended runtime sessions only last for 30 minutes though. My current plan to deal with this is to reschedule the session using session.start(at: )

I am currently thinking about doing it like this:

  • User selects opponent and goes to bed

  • App gets the amount of time the user needs to sleep for to surpass opponent, "sleepTime"

  • App schedules an extended runtime session to activate sleepTime seconds in the future

  • sleepTime seconds in the future the session activates and the app checks to see how long the user has actually slept since they went to bed.

  • If the user has slept less than the sleepTime needed to surpass the opponent the app will reschedule the extended runtime session for sleepTime - amountSleptSoFar == "sleepRemaining" seconds, in the future.

  • sleepRemaining seconds in the future the session will activate and check to see how long the user has actually slept for again.

  • If the user has slept less than the time needed to surpass the opponent then the session is rescheduled like before

  • If the user has slept more than the time needed to surpass the opponent then the app uses an API to update the game.

  • It is important that the game is updated as soon as the user surpasses an opponent and I don't want to set up a database to store sleep information and then update the game using the database data as soon as the database is updated.

Does this seem like an okay approach? And more importantly is it possible to do? From what I've read and implemented so far it seems possible but please let me know if I'm missing something. The one thing I'm unsure about is if I can use session.start(at: ) when the app is not currently open. If I can't reschedule using that then how else could I do what I need to do?

Is this a good approach for creating this Apple Watch sleep game feature?
 
 
Q