0

Currently, the notification is enable by pressing a button, but I'm not sure how to turn it into a toggle, so that when the toggle is off the notification isn't scheduled. Here is what I have so far:

 Button("Allow notifications"){
      let center = UNUserNotificationCenter.current()
      let content = UNMutableNotificationContent()
      content.title = "Isha is at \(isha)"
      content.body = "Time to pray!"
      content.categoryIdentifier = "alarm"
      content.sound = UNNotificationSound.default
      let dateComponents = Calendar.current.dateComponents([.hour, .minute], from: notiisha)
      let trigger = UNCalendarNotificationTrigger(dateMatching: dateComponents, repeats: true)
      let request = UNNotificationRequest(identifier: UUID().uuidString, content: content, trigger: trigger)
      center.add(request)
 }
Joakim Danielson
  • 43,251
  • 5
  • 22
  • 52
Joe
  • 11
  • 1

0 Answers0