fix scheduling notifications
This commit is contained in:
@@ -29,29 +29,37 @@ class LocalNotification {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public class func scheduleReminder(atTime time: Date, withTitle title: String) {
|
public class func scheduleReminder(atTime time: Date, withTitle title: String) {
|
||||||
let _ = LocalNotification.createNotificationCategory()
|
LocalNotification.testIfEnabled(completion: { result in
|
||||||
|
switch result{
|
||||||
let notificationContent = UNMutableNotificationContent()
|
case .success(_):
|
||||||
notificationContent.title = title
|
let _ = LocalNotification.createNotificationCategory()
|
||||||
|
|
||||||
notificationContent.badge = NSNumber(value: 1)
|
let notificationContent = UNMutableNotificationContent()
|
||||||
notificationContent.sound = .default
|
notificationContent.title = title
|
||||||
notificationContent.categoryIdentifier = LocalNotification.categoryName
|
|
||||||
|
notificationContent.badge = NSNumber(value: 1)
|
||||||
let calendar = Calendar.current
|
notificationContent.sound = .default
|
||||||
let time = calendar.dateComponents([.hour,.minute], from: time)
|
notificationContent.categoryIdentifier = LocalNotification.categoryName
|
||||||
|
|
||||||
var datComp = DateComponents()
|
let calendar = Calendar.current
|
||||||
datComp.hour = time.hour
|
let time = calendar.dateComponents([.hour,.minute], from: time)
|
||||||
datComp.minute = time.minute
|
|
||||||
|
var datComp = DateComponents()
|
||||||
let trigger = UNCalendarNotificationTrigger(dateMatching: datComp, repeats: true)
|
datComp.hour = time.hour
|
||||||
let request = UNNotificationRequest(identifier: UUID().uuidString, content: notificationContent, trigger: trigger)
|
datComp.minute = time.minute
|
||||||
UNUserNotificationCenter.current().add(request) { (error : Error?) in
|
|
||||||
if let theError = error {
|
let trigger = UNCalendarNotificationTrigger(dateMatching: datComp, repeats: true)
|
||||||
print(theError.localizedDescription)
|
let request = UNNotificationRequest(identifier: UUID().uuidString, content: notificationContent, trigger: trigger)
|
||||||
|
UNUserNotificationCenter.current().add(request) { (error : Error?) in
|
||||||
|
if let theError = error {
|
||||||
|
print(theError.localizedDescription)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case .failure(_):
|
||||||
|
// Todo: show enable this
|
||||||
|
break
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
private class func createNotificationCategory() -> UNNotificationCategory {
|
private class func createNotificationCategory() -> UNNotificationCategory {
|
||||||
|
|||||||
Reference in New Issue
Block a user