Could Widget receive remote notifications

I try to receive remote notifications in widgets(implemented through WidgetKit), but failed.

It known that enable remote notifications should register first by calling


UIApplication.shared.registerForRemoteNotifications()

but in widget cannot calling shared, it is available in widgets

@property(class, nonatomic, readonly) UIApplication *sharedApplication NS_EXTENSION_UNAVAILABLE_IOS("Use view controller based solutions where appropriate instead.");

and if try to init a UIApplication(by UIApplication()), the app will crash for more than one UIApplication instance.

Replies

Through research and investigation, the Notification Service Extension can receive remote notifications except silent notifications or those that only play a sound or badge the app’s icon by invoking - (void)didReceiveNotificationRequest:(UNNotificationRequest *)request withContentHandler:(void (^)(UNNotificationContent *contentToDeliver))contentHandler