1

It's working fine when application stay in background (remote notification). Problem is when I chatting with my one friend . New messages from other contacts I need to show like iOS notification alert banner like Facebook messenger. Also notifications available in my device notification list . I can't figure out how can do that ..

like this image I found a answered Displaying a stock iOS notification banner when your app is open and in the foreground? but it is iOS 10 . I need to support minimum iOS 9 and project is swift 2

Community
  • 1
  • 1
  • 1
    you can display a custom notification using UIview when you get message from another user while you are chating with some one else. you will get notification in did receive function in app delegate. then if the new notification is from different user then display custom view on top of the window. – Pankaj K. Feb 08 '17 at 12:36
  • @Prince .ok fine .. how can i make notification sound –  Feb 08 '17 at 15:13
  • to play notification sound you can search over SO and this might be help you. http://stackoverflow.com/questions/3277811/play-local-notification-default-sound-when-displaying-uialertview – Pankaj K. Feb 09 '17 at 07:04

1 Answers1

0

Adding that completionHandler line to appDelegate method solved my problem:

//Called when a notification is delivered to a foreground app.
@available(iOS 10.0, *)
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
print("User Info = ",notification.request.content.userInfo)

completionHandler([.alert, .badge, .sound])
}