How to reload timeline of iOS 14 widget from notification response?

Sarvesh picture Sarvesh · Jul 6, 2020 · Viewed 8k times · Source

I'm making a home screen widget for iOS 14 using the new WidgetKit and I want my widget timeline to refresh when the user responds to a notification.

This is what my code looks like currently:

func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
        
    if response.actionIdentifier == "actionIdentifier" {        
        print("notification response received")
        WidgetCenter.shared.reloadAllTimelines()
    }

    completionHandler()
}

But my widget is not updated when the user responds to the notification. The print statement gets printed, so I know my app is receiving the response. The widget also gets refreshed when I call reloadAllTimeLines() anywhere else in my app, so I'm sure my widget extension is implemented correctly. But it's not updating in the above scenario.

Is this a bug or am I doing something wrong? Or is there another way to reload a widget timeline after the user responds to a notification.

Answer

Sarvesh picture Sarvesh · Jul 9, 2020

This seems to be fixed in iOS 14 beta 2. The widget now correctly updates when refreshAllTimelines() is called from the notification response.