Reputation: 501
Actually I need to read those notification instead of tapping the notification banner.
I have used this code
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {}
But this function only gets called when the app is in foreground or the notification banner gets tapped by the user. I need bunch of code to read the code in Background. I am using OneSignal Push Notification service.
Upvotes: 2
Views: 939
Reputation: 235
You can able get the notification responce before notification banner shows. no need tap on notification banner.
@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
}
Upvotes: 1