0

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?

Community
  • 1
  • 1
Flasgod
  • 101
  • 2
  • When your app is in the foreground, presentation of alert messages is 100% handled by your code, so you have some code somewhere that is displaying that alert view – Paulw11 Apr 07 '17 at 23:15
  • I have looked _literally_ everywhere and I'm pretty certain that I do not raise any alerts. In fact I don't use `UIAlertController` in the entire project, but I'll keep looking into it. Thanks! – Flasgod Apr 07 '17 at 23:24
  • You need to pass none to the completion handler https://developer.apple.com/reference/usernotifications/unnotificationpresentationoptionnone?language=objc – Paulw11 Apr 07 '17 at 23:29
  • Solved. It was OneSignal raising up the alert. Apparently it does this by default (which I think is bold on their part) just need to edit the settings when you initialize OneSignal. – Flasgod Apr 10 '17 at 14:04

0 Answers0