I was very excited to see the addition of push notifications for widgets. However upon further inspection, the way it is implemented seems too limiting for real life apps.
I have an app for time tracking with my own backend. The app syncs with my backend in the main executable (main target). My widgets are more lightweight as they only access data in the shared app container, but they don't perform sync with the server directly to avoid race conditions with the main app.
I was under the impression that the general direction of the platform is to be doing most things in the main app target (also App Intents work that way for the most part), so the fact that the WidgetPushHandler just calls the widget's method to reload the timeline is very unfortunate. In an ideal scenario I also need the main app to be 'woken up' to perform the sync with the server, and once that's done I'd update the widget's timeline and where I would just read data from the shared app container.
So, my questions are:
- What is the recommended way of updating the widgets when this push notification arrives in the case that the main app target needs to perform the sync first?
- Is there any way how to detect that the method
func timeline(for configuration: InteractiveTrackingWidgetConfigurationAppIntent, in context: Context)
was called as a result of the push notification being received?
-
Can I somehow schedule a background task from the widget's reloadTimeline() function?
-
How can I get the push token later, in case that I don't save it right away the first time the
WidgetPushHandler's pushTokenDidChange()
is called?
Thank you for your work on this and hopefully for your answers.
FB19356256