Local notifications are not firing in ios10

后端 未结 3 1251
不思量自难忘°
不思量自难忘° 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: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!)
        }
    }
    

提交回复
热议问题