实际上我需要阅读那些通知而不是点击通知横幅。
我用过这段代码
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {}
但是只有当应用程序处于前台或用户点击通知横幅时才会调用此函数。 我需要一堆代码来读取后台代码。 我正在使用 OneSignal 推送通知服务。
最佳答案
您可以在通知横幅显示之前获得通知响应。无需点击通知横幅。
@available(iOS 10.0, *)
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
completionHandler([.sound, .alert, .badge])
UIApplication.shared.applicationIconBadgeNumber = 0
alertRemoteNotification(notification.request.content.userInfo as NSDictionary
}
关于ios - 如果应用程序未在 Swift iOS 中运行,如何读取一个信号通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50761976/