I am using push notification in my app and performing segue on click of notification but the problem is if the app is on some view and notification comes of that same view, then segue is performed on same view and same view comes on that view. I don't want this to happen if the view is same then it should not perform segue. Here is my code
 if application.applicationState == UIApplicationState.background{
        let moduleName = userInfo.value(forKey: "click_action") as! String
        let timestamp = Int64(date.timeIntervalSince1970)
        let description = userInfo.value(forKey: "body") as! String
        let title = userInfo.value(forKey: "title") as! String
        let entity = NSEntityDescription.entity(forEntityName: "Notifications", in: DataBaseController.persistentContainer.viewContext)
        let managedObj=NSManagedObject(entity: entity!, insertInto: DataBaseController.persistentContainer.viewContext)
        managedObj.setValue(moduleName, forKey: "click")
        managedObj.setValue(description, forKey: "body")
        managedObj.setValue(timestamp, forKey: "timestamp")
        managedObj.setValue(title, forKey: "title")
        DataBaseController.saveContext()
        if (homeVC != nil){
            homeVC?.performSegue(withIdentifier: moduleName, sender: homeVC)
        }
    }
}
Methods In homeView Controller
  //MARK:- Navigation Methods
override func prepare(for segue: UIStoryboardSegue, sender: Any?)
{
    let backItem = UIBarButtonItem()
    backItem.title = "Home"
    navigationItem.backBarButtonItem = backItem // This will show in the next view controller being pushed
    if(segue.identifier == "notificationconnew"){
        let notObj = segue.destination as! NotificationsTableViewController
        notObj.homeVC = self
    }
}
override func shouldPerformSegue(withIdentifier identifier: String, sender: Any?) -> Bool {
    if identifier == segueString && self.navigationController?.viewControllers.last is MyEarningViewController{
        return false
    }
    else{
        return true
    }
}
Declaration of homeVc object in App Delegate
class AppDelegate: UIResponder, UIApplicationDelegate{
var window: UIWindow?
var notification : NSDictionary?
var homeVC : HomeViewController?
lazy var dBhandler = DBHandler()
let date = NSDate()
And giving instance in viewDidLoad of HomeViewController
// Giving instance of HomeViewController to AppDelegate
    let appDele = UIApplication.shared.delegate as! AppDelegate
    appDele.homeVC = self
Check this enter image description here
 
     
    