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?