'Why InApp message show popup first in IOS?

Try to push InApp message to my IOS Apps using swift. But I got popup notification instead of template design. After i click the notification , only then the template is showing.

How to make the template message appear right away without click the notification

When push in app message it will go to code below and show notification, not the card template

It goes to 2 functions

1.

func userNotificationCenter(_ center: UNUserNotificationCenter,
                                willPresent notification: UNNotification,
                                withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
        let userInfo = notification.request.content.userInfo
        if let messageID = userInfo[gcmMessageIDKey] {
            print("Message ID: \(messageID)")
        }
        handleFCM(with: userInfo)
        completionHandler([.alert,.badge])
    }
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
        if let messageID = userInfo[gcmMessageIDKey] {
            print("Message ID: \(messageID)")
        }
        handleFCM(with: userInfo)
        completionHandler(UIBackgroundFetchResult.newData)
    }

It shows notification enter image description here

And then when notif click show the in app enter image description here

My Expectation is: Just show the in app with trasparent background without click notification first



Solution 1:[1]

You cannot show a random UI INSTEAD of a user notification.*

What you can do is to customize the UI of your user notification. In this case the UI of user notifications will be look as you implement. Tapping on a notification will behave as previously. Here is an introduction.

Besides, you can add custom actions (buttons) to user notifications, that can fire some code, for example a background task to do something without opening your app, or actually opening your app in a special state. Here is an introduction to the concept.

You can also make a push notification silent. In this case the UI won't be shown at all, but your app will be launched in background and given a chance to do something. Though, you won't be able to show any UI (until the user manually launches the app). Here is Apple's docs about it.

*You can choose whether to show a user notification only when your app is running in the foreground. In this case you can implement whatever you like.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1