0
votes

I am using Urban Airship to receive push notification in my iOS 10 (Swift) app. I am running with following problems, requesting your help to resolve.

Unable to hide notification when app is running foreground

To hide notification, I have tried following tasks..

  1. Remove implementation of delegate method func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void)

  2. I tried to pass completionHandler(UNNotificationPresentationOptionNone) to escape / hide notification toast, but "UNNotificationPresentationOptionNone" is no more available.

  3. completionHandler([]) -- This does not work. I have tried to pass "UNNotificationPresentationOptionNone" in

Clear Notification

How to clear/remove delivered(Once user read or cancel) notification from list and update the badge icon accordingly.

Thanks

1
@rmaddy could you please tell me , which method gets executed when the app is in background and receive notification?ArgaPK

1 Answers

0
votes

Foreground Presentation Handling

There are two ways to handle foreground presentation options on iOS10+ with the Urban Airship SDK. If you have an instance of UAPushNotificationDelegate configured on the Urban Airship SDK then presentation options will be delegated to presentationOptions and handled per push. For example:

@available(iOS 10.0, *)
func presentationOptions(for notification: UNNotification) -> UNNotificationPresentationOptions {
    return [.alert]
}

You can return [] to not present anything.

Otherwise, if you do not have the aforementioned delegate configured you can disable all foreground presentation options by setting the defaultPresentationOptions.

UAirship.push().defaultPresentationOptions = []

Clearing Notifications

On iOS10+ you can clear your app's notifications via the shared instance of UNUserNotificationCenter which provides a removeAllDeliveredNotifications()method. To maintain compatibility on older versions of iOS you can fall back to setting the badge to zero-- more information about that here.

if #available(iOS 10.0, *) {
    UNUserNotificationCenter.current().removeAllDeliveredNotifications()
} else {
    UIApplication.shared.applicationIconBadgeNumber = 0;
};