2

我在设置由 DateComponents 确定的 UNCalendarNotificationTrigger 类型的通知时遇到问题

//set content
let content = UNMutableNotificationContent()
content.title = "My Notification Management Demo"
content.subtitle = "Timed Notification"
content.body = "Notification"
content.body = "Notification pressed \(pressed) times"
content.categoryIdentifier = "message"

//set trigger possible problem
let formatted = DateFormatter()
formatted.dateFormat = "yyyy-MM-dd'T'HH:mm:ssxxxxx"
formatted.date(from: "2018-01-19T02:29:50+0000")

var dateInfo = DateComponents()
dateInfo.calendar = formatted.calendar

let trigger = UNCalendarNotificationTrigger(
    dateMatching: dateInfo,
    repeats: false
)

//Create the request
let request = UNNotificationRequest(
    identifier: "my.notification",
    content: content,
    trigger: trigger
 )

 //Schedule the request
 UNUserNotificationCenter.current().add(request) { (error : Error?) in
     print("all ok")
 }

当我请求获取待处理的通知时,数组很宽。

  UNUserNotificationCenter.current().getPendingNotificationRequests(completionHandler: {requests -> () in
        print("\(requests.count) requests -------")
        for request in requests{
            print(request.identifier)
        }
    })
4

0 回答 0