'Daily local notification with pre-launch conditions check
I've added a function to show daily local notifications, but I need to check the database before sending notifications and send a message only if the conditions are met. Please, can you give me some advice on the best way to implement it? Thanks in advance!
func scheduleTriggerNotification(title: String, body: String, subtitle: String, categoryIdentifier: String, hour: Int, minutes: Int) {
let content = UNMutableNotificationContent()
content.title = title
content.body = body
content.subtitle = subtitle
content.categoryIdentifier = categoryIdentifier
content.sound = UNNotificationSound.default
var dateComponents = DateComponents(timeZone: .current)
dateComponents.hour = hour
dateComponents.minute = minutes
let trigger = UNCalendarNotificationTrigger(dateMatching: dateComponents, repeats: true)
let request = UNNotificationRequest(identifier: UUID().uuidString, content: content, trigger: trigger)
notificationCenter.add(request)
}
// Checking the database before triggering a notification
func checkNotification() -> (Bool, String) {
var trigger: Bool = false
var note: String = ""
// Database checking
return (trigger, note)
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
