Been researching this topic, curious if it's possible to schedule a function to run at a specific time same way you can schedule local notifications to trigger at a specific time. Would need this to run even if the app is closed or in the background.
Use Case:
I'm working on an app that that currently sends the user a random message daily "from an array of possible messages" as a local notification. This local notification is triggered at a specific time a user has specified from a datepicker. All of this is working as expected even if the app is closed.
Now I'm trying to figure out a way to show the content of the last random notification received inside the app. I would like to set a labels text to the body.content "random message" of the local notification... but only after they have received the notification. I don't want to show it in the app before it's been delivered. Example: user opens app, sets the local notification time to be received at 3pm. User closes app, notification is received at 3pm, they open the app at 4pm, a label inside the app displays the same message that they received as a notification. Message in app should stay the same till the next day at 3pm since the local notification is set to repeat.
The problem, apparently you can't retrieve the contents of a delivered local notification. Which is why I was wondering if it's possible to schedule a function at a specific time. If so I could then save the generated message as a userdefault value, then trigger a UNTimeIntervalNotification in like 5 seconds and use the same saved value. When the app is opened, I could update the label.text using the saved value. That way, each time they open the app, the label in the app would always be the same as the last notification received.
Im new to swift language, any other suggestions on possible solutions to this problem would be greatly appreciated.