I\'m using UNUserNotificationCenter
for ios 10. For testing, I\'m setting a local notification for 10 seconds from current time.
This is what I tried,
Set NSDateComponents like:
NSDateComponents *components = [calendar components:NSCalendarUnitYear|NSCalendarUnitMonth|NSCalendarUnitDay|NSCalendarUnitHour|NSCalendarUnitMinute|NSCalendarUnitSecond|NSCalendarUnitTimeZone fromDate:[[NSDate date] dateByAddingTimeInterval:10]];
Or use a time trigger instead of a calendar trigger
@IBAction func sendNotification(_ sender: Any) {
let content = UNMutableNotificationContent()
content.title = "Hello"
content.body = "Ved Rauniyar !!!"
// content.badge = 1
content.sound = UNNotificationSound.default()
// Deliver the notification in five seconds.
let trigger = UNTimeIntervalNotificationTrigger.init(timeInterval: 5, repeats: false)
let url = Bundle.main.url(forResource:"ved", withExtension: "png")
let attachment = try? UNNotificationAttachment(identifier: "FiveSecond",
url: url!,
options: [:])
content.attachments = [attachment!]
let request = UNNotificationRequest.init(identifier: "FiveSecond", content: content, trigger: trigger)
// Schedule the notification.
let center = UNUserNotificationCenter.current()
center.add(request) { (error) in
// print(error!)
}
}