Messaging Notification is not displaying on phone but data is printing in console

This method is only being called when the app is on foreground:

func messaging(_ messaging: Messaging, didReceive remoteMessage: MessagingRemoteMessage) {
        print("Received data message: /(remoteMessage.appData)")

So by default it is not displaying the notification when the app is in background or not running. As I open the app it instantly print the notification. So why it is not showing when in background or not running state?