0

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

lauwis
  • 323
  • 1
  • 4
  • 15
  • What exactly you wanted to have on your screen once push received? Can you please share screenshot? – RJ168 Feb 17 '22 at 07:11
  • ...And also your code that triggers the notification. – lazarevzubov Feb 17 '22 at 07:20
  • @RJ168 i shared the screenshot – lauwis Feb 17 '22 at 09:59
  • @lazarevzubov it goes to will present for every push in app message – lauwis Feb 17 '22 at 09:59
  • @lauwis Push notification flow is working as expected, it will show the drawer message from top when app is not in forground mode. When app is running then you can receive the control in app delegate method to display your custom view or alert. – RJ168 Feb 17 '22 at 13:27
  • Are all in app messaging work as push notification flow ? Because, what I imagine, in app messaging is different than push notification flow – lauwis Feb 17 '22 at 14:09

1 Answers1

0

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.

lazarevzubov
  • 1,767
  • 2
  • 14
  • 24
  • I think that's not a random UI, it's firebase in app messaging that i push actually. And also the notification shows when apps in background, isn't inapp message is only show when app is in foreground ? – lauwis Feb 17 '22 at 11:38
  • In your 1st screenshot it's just a regular user notification, a push notification to be precise. It's not the app UI, it's the iOS standard UI for user notifications (which, as I mentioned in my answer, you can modify). It doesn't matter if your push notification was sent via FCM or APNs directly – in both cases iOS receives it, delivers it to your app, and shows it if appropriate. In your second screenshot, it seems to be just your app running and showing some UI – it's not entirely clear from the screenshot, though. – lazarevzubov Feb 17 '22 at 13:11
  • So, are all in app messaging is going the same as push notification flow ? – lauwis Feb 17 '22 at 14:10
  • iOS doesn't have a built-in notion called "In-App Messaging". It's a wider UX concept that you can implement by different means. If your app is open, when you need to show an "in-app message", you can implement any UI you like, of course. But if it's closed, the only way to show something to the user is user notifications. They can be triggered by push notifications (sent from your server via FCM or APNs) or local notifications (sent from your app)–judging from the described scenario, this is your case. – lazarevzubov Feb 18 '22 at 07:27