Will
Will

Reputation: 5470

Notification makes sound but does not display anything

For my app I am looking to implement a local notification system.

My code to schedule a notification is as follows:

func scheduleNotification(_ Name:String, _ Time:DateComponents){
        let center = UNUserNotificationCenter.current()
        let notification = UNMutableNotificationContent()
        notification.title = Name
        notification.sound = UNNotificationSound.default()


        var trigger = UNCalendarNotificationTrigger(dateMatching: Time, repeats: false)

        let identifier = Name

        let request = UNNotificationRequest(identifier: identifier, content: notification, trigger: trigger)
        center.add(request)

    }

Now that worked yesterday, but not it no longer does. In both simulator and device.

I've tried the suggestion here to no avail: Local Notifications make sound but do not display (Swift)

What I have tried:

Upvotes: 2

Views: 113

Answers (1)

jignesh Vadadoriya
jignesh Vadadoriya

Reputation: 3310

I think you need to set body of notification. add this line too below notification.title = Name line

notification.body = "Hello Notification"

For more check Apple doc.

Upvotes: 2

Related Questions