我正在尝试安排本地iOS通知,但没有弹出通知。我已经100%验证了adjustedDate
变量有效,并且已经通过其nextTriggerDate
函数确认了通知触发器的日期正确。
我还验证了UNUserNotificationCenter
在AppDelegate
中请求通知权限,并且工作正常。
let content = UNMutableNotificationContent()
content.title = "Test"
content.body = "More testing"
content.sound = UNNotificationSound.default()
let trigger = UNCalendarNotificationTrigger(dateMatching: Calendar.normalizedCalendar.dateComponents([.year, .month, .day, .hour, .minute, .calendar], from: adjustedTime), repeats: true)
let request = UNNotificationRequest(identifier: UUID().uuidString, content: content, trigger: trigger)
UNUserNotificationCenter.current().add(request) {
error in
if error != nil {
self.out("Failed to add notification: \(error!.localizedDescription)")
} else {
}
}