Ahsan
Ahsan

Reputation: 501

How to Read One signal notification if the App is not running in Swift iOS

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

Answers (1)

Praveen Gowlikar
Praveen Gowlikar

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

Related Questions