I'm trying to create the app that updates the widget when the server sends a push notification. But I'm not sure if this is possible. Has anyone developed the app related to this? If that's not possible, I'll try to figure out another way not using push notification.
-
It seems to me like a notification extension may be able to trigger the refresh method on WidgetKit. Have you tried something like that? Or what else did you try? – EmilioPelaez Sep 01 '22 at 11:12
-
Haven't tried it yet. I just found this page (https://stackoverflow.com/questions/62754880/how-to-reload-timeline-of-ios-14-widget-from-notification-response). According to Jordan H, it seems possible, but not real-time update. I'll test about that and post the results! – n3bular Sep 01 '22 at 11:52
2 Answers
I was able to trigger the remote notification using the userNotificationCenter(_:didReceive:withCompletionHandler:) and application(_:didReceiveRemoteNotification:fetchCompletionHandler:) methods of UNUserNotificationCenterDelegate.
What exactly I wanted was to change the widget in real time when a silent push came.
However, according to Apple's official documentation...
Because silent push has limitations (1. number per hour limit, 2. Possibility not to be delivered), it was difficult to update the widget in real time.
So my conclusion is,
It is possible to update the widget using remote notification, but it is difficult to use it in a way that updates the widget in real time in the background.

- 33
- 4
The suitable solution is to start a CLLocationManager
in the background.
After that, your app can run in the background to execute codes (without user terminates/kills it). Then you can apply a Real-time event listener to refresh Widget info.
You can reduce the accuracy and increase distanceFilter to reduce power consumption. It is like you just keep app in background but don't need Device location data.

- 504
- 1
- 9