如果应用程序不是 运行 in Swift iOS 如何阅读一个信号通知
How to Read One signal notification if the App is not running in Swift iOS
实际上我需要阅读那些通知而不是点击通知横幅。
我用过这个代码
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
}
实际上我需要阅读那些通知而不是点击通知横幅。
我用过这个代码
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
}