Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jacobsapps/c03de09730b6834382e8ea0a9e5843d2 to your computer and use it in GitHub Desktop.
Save jacobsapps/c03de09730b6834382e8ea0a9e5843d2 to your computer and use it in GitHub Desktop.
func scheduleAlarm(at schedule: Alarm.Schedule) async throws {
// primary action button, that stops the alarm
let stopButton = AlarmButton(
text: "Mmm, Elvanse",
textColor: .white,
systemImageName: "checkmark.circle"
)
// what gets presented by the alarm - wraps the button
let alertPresentation = AlarmPresentation.Alert(
title: "Take your meds!",
stopButton: stopButton
)
// other customisation - wraps the presentation
let attributes = AlarmAttributes(
presentation: AlarmPresentation(alert: alertPresentation),
metadata: ADHDMetadata(),
tintColor: Color.orange
)
// alarm settings - wraps schedule and attributes
let alarmConfiguration = AlarmManager.AlarmConfiguration<ADHDMetadata>
.alarm(
schedule: schedule,
attributes: attributes
)
// finally schedules the alarm
_ = try await AlarmManager.shared.schedule(
id: UUID(),
configuration: alarmConfiguration
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment