如何从通知响应重新加载iOS 14小部件的时间轴? [英] How to reload timeline of iOS 14 widget from notification response?
问题描述
我正在使用新的WidgetKit为iOS 14创建主屏幕小部件,我希望我的小部件时间轴在用户响应通知时刷新.
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()
}
但是,当用户响应通知时,我的窗口小部件未更新.打印了打印语句,因此我知道我的应用程序正在接收响应.当我在应用程序的其他任何地方调用reloadAllTimeLines()
时,小部件也会刷新,因此我确定我的小部件扩展名正确实现.但在上述情况下并没有更新.
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.
推荐答案
这似乎已在iOS 14 beta 2中修复.现在,从通知响应中调用refreshAllTimelines()时,小部件现在可以正确更新.
This seems to be fixed in iOS 14 beta 2. The widget now correctly updates when refreshAllTimelines() is called from the notification response.
这篇关于如何从通知响应重新加载iOS 14小部件的时间轴?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!