UNCalendarNotificationTrigger doesn't get stored unless repeats is true

后端 未结 3 1768
Happy的楠姐
Happy的楠姐 2021-01-05 22:58

I\'ve noticed that if I create an UNCalendarNotificationTrigger with a custom date it does\'t get added unless i put: let trigger = UNCalendarNotificatio

3条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-06 00:03

    UNCalendarNotificationTrigger creates the schedule for which a notification should occur, but it does not do the scheduling. For this you need to create a UNNotificationRequest and then add this to the notification center. Something along the lines of:

        let request = UNNotificationRequest(identifier: "MyTrigger", content: content, trigger: trigger)
        UNUserNotificationCenter.current().add(request) { error in
            if let error = error {
                // Do something with error
            } else {
                // Request was added successfully
            }
        }
    

提交回复
热议问题