2

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:

  • Testing with the app force closed
  • Testing with the app in the background
  • Changing identifiers
Community
  • 1
  • 1
Will
  • 4,942
  • 2
  • 22
  • 47

1 Answers1

2

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.

jignesh Vadadoriya
  • 3,244
  • 3
  • 18
  • 29
  • I have received local notification but after 5 seconds automatically dismiss the notification popup, if any body give the suggestion to stay the popup more than 5 seconds? – Iyyappan Ravi Jan 21 '19 at 06:42