Swift 4中UNCalendarNotificationTrigger中的问题

时间:2018-01-19 02:58:31

标签: ios swift nsdatecomponents unusernotificationcenter usernotifications

我在设置由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)
        }
    })

0 个答案:

没有答案