Swift iOS 12 Beta UNUserNotification无法触发

时间:2018-08-13 19:33:09

标签: ios swift notifications unusernotificationcenter

我正在尝试安排本地iOS通知,但没有弹出通知。我已经100%验证了adjustedDate变量有效,并且已经通过其nextTriggerDate函数确认了通知触发器的日期正确。

我还验证了UNUserNotificationCenterAppDelegate中请求通知权限,并且工作正常。

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 {
    }
}

0 个答案:

没有答案