Why isn't my local notification getting delivered in the background?

My app is supposed to deliver a local notification in the background, but it isnt. The notification works when the app is in the foreground but it just fails to work otherwise. Please help me.

Here is my code:


import UIKit

import CoreLocation

import UserNotifications


class ViewController1: UIViewController, CLLocationManagerDelegate, UNUserNotificationCenterDelegate {

    override func viewDidLoad() {

        super.viewDidLoad()
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge]) {

            (success, error) in

            if error != nil {

                print("Authorization failed")

            }

        }

    }

    

    
    func sendNotification(inSeconds: TimeInterval, completion: @escaping (_ Success: Bool)->()){

        let trigger = UNTimeIntervalNotificationTrigger(timeInterval: inSeconds, repeats: false)

        let content = UNMutableNotificationContent()

        content.title = "Important question:"

        content.body = "Have you locked your door?"

        content.sound = .defaultCriticalSound(withAudioVolume: 20)

        

        

        let request = UNNotificationRequest(identifier: "customNotification", content: content, trigger: trigger)

        UNUserNotificationCenter.current().add(request) { (error) in

            if error != nil{

                completion(false)

            }else{

                completion(true)

            }

        }

    }

var isAtHome = 0
        
            while value < 100 && isAtHome == 0{

                deliverNotification()

                isAtHome = 1


            }

            while value > 100 && isAtHome == 1{

                isAtHome = 0


            }


            return value

        }


    }
}


@CoolCraftsBayarea1 Did you find a solution? facing the same issue, using a UNUserNotificationCenterDelegate and it is not triggered for Local push notification in background

Why isn't my local notification getting delivered in the background?
 
 
Q