I'm creating an iOS-Native app. I'm using XCode 8, testing on iOS10, using swift 3.
I'm dealing with APNS and sending Remote notifications (through OneSignal).
The notifications work flawlessly outside my app (when it is in background). However, when I have the app in foreground, no matter what I pass into the completionHandler()
(ex. [.alert, .sound]
, or [.sound]
or []
) the system creates a UIAlertController
with the contents of the notification (title and body) and presents it to the user. This is incredibly obnoxious as a user-interface and I would imagine there is some way to work around it.
I'm implementing the UNUserNotificationCenterDelegate
as follows:
extension ViewController: UNUserNotificationCenterDelegate{
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
//This is my BRYXBanner notification presentation/
let banner = Banner(title: notification.request.content.title, subtitle: notification.request.content.body, image: nil, backgroundColor: .blue, didTapBlock: nil)
banner.alpha = 0.9
banner.animationDuration = 0.2
banner.position = .top
banner.show(genView, duration: 3.0)
completionHandler([])
}
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
switch(response.actionIdentifier){
//switch cases for actions/
default: break
}
completionHandler([])
}
}
I'm also implementing the UIApplicationDelegate
but that one simply has print statements.
What I'm seeing when I receive a notification is this: Screenshot of a custom notification I sent for this
I've seen others have had this issue (How to disable default notification alert view on iOS remote notifications?) but have no idea how they got around it. Most posts simply lead to "oh, I fixed it" with no further explanation.
How can I bypass the showing of this notification, whether it be silencing the notification (if that works) or dealing with the completion handler or intercepting the notification before it is displayed?