Handle Push notification during the App running in foreground using swift 4


Push notification during the App running in foreground

iOS App is running in 2 mode either the user is interacting with app (foreground)  or minimize  the app (background). if we are talking   about the firebase push notification  then we have to handle by other way because iOS 10 to above provide the custom  local  notification for handling this type of issue when app is running in foreground.

Here I have taken the example of Firebase Push Notifaction.

1: First Set up firebase Push notification in App.

2: Open Appdelegate.swift File:

write this Code for checking the App is running on iOS 10 to above or less .

3:  It will Check weather your app is running in iOS 10 to above or less if iOS app is running on iOS 10 or above then it will assigned the local push notification for handle the foreground app.

4: Now return  the local push notification type like this:

Note:  UNNotificationPresentationOptions.alert  – it will return a alert.

5: It will work when your app is running on foreground and someone send the notification .

6: Now we have to handle the Tap also for this write this function

Note: This method will call when the user tap on foreground Notification.

7: Fire base also provide the other function for iOS 10 to above if token expire , for this write this method to handle this type of case.


















. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


  • ravindra K
    Nice tutorial,
    is there any way to show a notification to the user when the app is in the foreground for iOS 10 and below?
    • kunal prasad (Moderator)
      For iOS 10 it will work but for less than iOS 10 you will have to use custom notification bar.
  • Rajneesh
    This is really informative tutorial , but i have a question , if backend guy give me notification in data payload , then how i hanlde when app is in terminated state.
  • css.php

    Webkul is a truly trusted and supported IT Company to develop business ideas for e-commerce. They provide professional support after deploying the solution to production and be responsible to act for fixing the reported issues or system errors. We highly encourage to deal with Webkul for business development.

    Hussein Zawia

    Hussein Zawia

    Co-founder, 24Dokan

    Talk to Sales


    Live Chat
    Start a Project

      Message Sent!

      If you have more details or questions, you can reply to the received confirmation email.

      Back to Home