Local notifications are not firing in ios10

后端 未结 3 1228
不思量自难忘°
不思量自难忘° 2021-01-12 15:55

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,

相关标签:
3条回答
  • 2021-01-12 16:07

    Set NSDateComponents like:

    NSDateComponents *components = [calendar components:NSCalendarUnitYear|NSCalendarUnitMonth|NSCalendarUnitDay|NSCalendarUnitHour|NSCalendarUnitMinute|NSCalendarUnitSecond|NSCalendarUnitTimeZone fromDate:[[NSDate date] dateByAddingTimeInterval:10]];
    
    0 讨论(0)
  • 2021-01-12 16:08

    Or use a time trigger instead of a calendar trigger

    0 讨论(0)
  • 2021-01-12 16:22
    @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!)
        }
    }
    
    0 讨论(0)
提交回复
热议问题