Redeem Now
Read More
Read now

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.


















. . .

Comments (3)

Add Your Comment

  • 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
      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
    Hire Us!
    Brief us about your requirements and we'll get back to you.
    Woo! Hooy!
    We have just recieved your project brief and our expert will contact you shortly.
    Send Again