When I call the completion handler from the following User Notification Center delegate function and pass UNNotificationPresentationOptions.sound
I still get the notification banner:
override func userNotificationCenter(
_ center: UNUserNotificationCenter,
willPresent notification: UNNotification,
withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void
) {
completionHandler(.sound)
}
All I want is a way to just make a notification sound without showing the notification while the app is in the foreground.
Any ideas?
This is how I am requesting authorization:
[[UNUserNotificationCenter currentNotificationCenter] requestAuthorizationWithOptions: (UNAuthorizationOptionBadge | UNAuthorizationOptionSound)
completionHandler: ^ (BOOL granted, NSError * _Nullable error) {
}];
This is the notification request:
var notification = UNMutableNotificationContent()
if (notification != nil) {
notification.categoryIdentifier = "id"
notification.sound = .default
notification.title = "title"
notification.body = "body"
request = UNNotificationRequest(
identifier: NSUUID().uuidString,
content: notification,
trigger: nil
)
UNUserNotificationCenter.current().add(request) { (error) in
}