0

I am facing a strange issue in my iOS app. When my app is in foreground and Push is received it is displaying in notification center and also same is displayed in an alert.

But I have not written any alert displaying code in any of push notification received delegate methods in Appdelegate.

How to avoid this unwanted alertview when the app is in the foreground. ??

ucMedia
  • 4,105
  • 4
  • 38
  • 46
Amol Hirkane
  • 75
  • 1
  • 11

1 Answers1

3

It is due to the Delegate implemented

Objective-C

- (void)userNotificationCenter:(UNUserNotificationCenter *)center 
                   willPresentNotification:(UNNotification *)notification 
                     withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler {

             completionHandler(UNNotificationPresentationOptionAlert); // SHOWS ALERT
}

Swift 3

func userNotificationCenter(_ center: UNUserNotificationCenter,
                                willPresent notification: UNNotification,
                                withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
    completionHandler(.alert)
}

In iOS 10 you can show notification also when is in foreground. You can check by adding badge only in completionHandler or comment completionHandler

Ref : Displaying a stock iOS notification banner when your app is open and in the foreground?

Abhishek Thapliyal
  • 3,497
  • 6
  • 30
  • 69