Skip to content

Commit

Permalink
iOS and WatchOS add sound to alarms
Browse files Browse the repository at this point in the history
WatchOS add sound and haptic feedback when set a notif alarm
  • Loading branch information
mulot committed Aug 23, 2024
1 parent 0d4b31f commit 25e4b0d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
3 changes: 3 additions & 0 deletions WatchOS WatchKit Extension/BeatTimeApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ struct ConvertView: View {

struct AlarmView: View {
@State var selection: String = BeatTime.beats()
@State private var notifCount = 0

func setNotification(msg: String, date: Date) -> Void {
if (date.timeIntervalSinceNow < 0) {
Expand Down Expand Up @@ -200,7 +201,9 @@ struct AlarmView: View {
}
Button("Set notif ", action: {
self.setNotification(msg: "@\(selection) .beats", date: BeatTime.date(beats: selection))
notifCount += 1
})
.sensoryFeedback(.success, trigger: notifCount)
}
}
}
Expand Down
2 changes: 0 additions & 2 deletions iOS/BeatTimeiOSApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,6 @@ struct AlarmSetView: View {
@State private var date = Date()
@State private var beats: String = BeatTime.beats()
@Query(sort: \Notification.date) private var notifications: [Notification]
//@State private var notifCount: Int = manager.notifications.count
//@Query private var notifications: [Notification] = manager.notifications
@Environment(\.modelContext) private var context

func setNotification(msg: String, date: Date) -> Void {
Expand Down
5 changes: 4 additions & 1 deletion iOS/LocalNotificationManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class LocalNotificationManager {
func requestPermission(notif: Notification) -> Void {
UNUserNotificationCenter
.current()
.requestAuthorization(options: [.alert, .badge, .alert]) { granted, error in
.requestAuthorization(options: [.alert, .badge, .sound]) { granted, error in
if granted == true && error == nil {
self.scheduleNotifications(notif: notif)
// We have permission!
Expand All @@ -55,6 +55,9 @@ class LocalNotificationManager {
func scheduleNotifications(notif: Notification) -> Void {
let content = UNMutableNotificationContent()
content.title = notif.title
content.sound = UNNotificationSound.default
//content.badge = 1
//UNUserNotificationCenter.current().setBadgeCount(1)

let trigger = UNTimeIntervalNotificationTrigger(timeInterval: notif.timer, repeats: false)
let request = UNNotificationRequest(identifier: notif.id, content: content, trigger: trigger)
Expand Down

0 comments on commit 25e4b0d

Please sign in to comment.