Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions RocketCall/Model/NotificationManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,16 @@ final class NotificationManager: NSObject, UNUserNotificationCenterDelegate {
let options: UNAuthorizationOptions = [.alert, .sound]

center.requestAuthorization(options: options) { granted, error in
if let error = error {
print("Notification authorization error: \(error.localizedDescription)")
}
}
}


// MARK: - μ•ŒλžŒ μ˜ˆμ•½ λ©”μ„œλ“œ
func addAlarm(_ alarm: Alarm) {
let notificationRepeatInterval = 9
let center = UNUserNotificationCenter.current()

// 1. λ‚΄μš©
Expand All @@ -53,7 +57,7 @@ final class NotificationManager: NSObject, UNUserNotificationCenterDelegate {
var dateComponents = DateComponents()
dateComponents.hour = alarm.hour
dateComponents.minute = alarm.minute
dateComponents.second = i * 9
dateComponents.second = i * notificationRepeatInterval

let trigger = UNCalendarNotificationTrigger(dateMatching: dateComponents, repeats: false)
let identifier = "\(alarm.id.uuidString)-\(i)"
Expand All @@ -69,7 +73,7 @@ final class NotificationManager: NSObject, UNUserNotificationCenterDelegate {
dateComponents.weekday = day.appleWeekDay
dateComponents.hour = alarm.hour
dateComponents.minute = alarm.minute
dateComponents.second = i * 9
dateComponents.second = i * notificationRepeatInterval

let trigger = UNCalendarNotificationTrigger(dateMatching: dateComponents, repeats: true)
let identifier = "\(alarm.id.uuidString)-\(day.rawValue)-\(i)" // idκ°€ λ™μΌν•˜λ―€λ‘œ ꡬ뢄지어주기 μœ„ν•΄ 뒀에 μš”μΌ μΆ”κ°€
Expand Down Expand Up @@ -99,6 +103,7 @@ final class NotificationManager: NSObject, UNUserNotificationCenterDelegate {

// MARK: - μŠ€λˆ„μ¦ˆ μ•ŒλžŒ μ˜ˆμ•½ λ©”μ„œλ“œ
func addSnoozeAlarm(title: String, originalId: UUID) {
let snoozeTime: TimeInterval = 60 * 5
let center = UNUserNotificationCenter.current()

// 1. λ‚΄μš©
Expand All @@ -109,7 +114,7 @@ final class NotificationManager: NSObject, UNUserNotificationCenterDelegate {
content.interruptionLevel = .timeSensitive // λ°©ν•΄ κΈˆμ§€μ—¬λ„ μ•ŒλžŒ

// 2. μ‹œκ°„ μ„€μ •
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 300, repeats: false)
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: snoozeTime, repeats: false)
let identifier = "\(originalId.uuidString)-Snooze"
let request = UNNotificationRequest(identifier: identifier, content: content, trigger: trigger)

Expand Down
4 changes: 2 additions & 2 deletions RocketCall/View/Alarm/AlarmRingViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ final class AlarmRingViewController: UIViewController {

do {
// 무음λͺ¨λ“œ μΌλ•Œλ„ μ†Œλ¦¬λ‚˜κ²Œ ν•˜κΈ°
try AVAudioSession.sharedInstance().setCategory(.playback, mode: . default)
try AVAudioSession.sharedInstance().setCategory(.playback, mode: .default)
try AVAudioSession.sharedInstance().setActive(true)

// ν”Œλ ˆμ΄μ–΄ μ„ΈνŒ…ν•˜κΈ°
Expand Down Expand Up @@ -130,7 +130,7 @@ final class AlarmRingViewController: UIViewController {
}

// 24초 λ”œλ ˆμ΄
DispatchQueue.global().asyncAfter(deadline: .now() + 27.0) {
DispatchQueue.global().asyncAfter(deadline: .now() + 9.0 * 3) {

let alarmToReschedule = Alarm(
id: payload.id,
Expand Down
Loading