Push Notifications

Hi, I am trying to add in a push notification but the send push notifications function does not seem to be working. Can someone help?

func sendNotification() {
        print("Bluetooth device disconnected. Sending notification.")
        
        let content = UNMutableNotificationContent()
        content.title = "Car Disconnected"
        content.body = "Please key in where you have left your car"
        content.sound = UNNotificationSound.default
        
        // Create a trigger to send the notification immediately
        let request = UNNotificationRequest(identifier: "BluetoothDisconnected", content: content, trigger: nil)
        
        UNUserNotificationCenter.current().add(request) { error in
            if let error = error {
                print("Error adding notification request: \(error.localizedDescription)")
            } else {
                print("Notification request added successfully.")
            }
        }
    }
Answered by Engineer in 788406022

First, to get the terminology correct: you are trying to add a local notification. A push notification is sent (pushed) from your server to send it.

In any case, the issue with this code is, despite commenting that you are creating a trigger, you do not, and passing nil as your trigger.

First, to get the terminology correct: you are trying to add a local notification. A push notification is sent (pushed) from your server to send it.

In any case, the issue with this code is, despite commenting that you are creating a trigger, you do not, and passing nil as your trigger.

Push Notifications
 
 
Q