Skip to content

Commit

Permalink
#8 feat: UserNotificationCenterService 타입 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
sanghyeok-kim committed Aug 3, 2023
1 parent abb8fb1 commit 9acb24b
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions Multimer/Multimer/Data/Service/UserNotificationCenterService.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//
// UserNotificationCenterService.swift
// Multimer
//
// Created by 김상혁 on 2023/08/02.
//

import Foundation
import UserNotifications

final class UserNotificationCenterService {
static func registerNotification(
ringtone: Ringtone?,
remainingSeconds: TimeInterval,
timerName: String,
notificationIdentifier: String?
) {
let content = UNMutableNotificationContent()
content.title = LocalizableString.appTitle.localized
content.body = LocalizableString.timerExpired(timerName: timerName).localized
content.sound = .default

if let ringtoneFileName = ringtone?.name, ringtone != .default1 {
content.sound = UNNotificationSound(
named: UNNotificationSoundName(rawValue: "\(ringtoneFileName).\(Constant.Ringtone.extension)")
)
}

if remainingSeconds <= .zero { return }
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: remainingSeconds, repeats: false)
guard let notificationIdentifier = notificationIdentifier else { return }
let request = UNNotificationRequest(identifier: notificationIdentifier, content: content, trigger: trigger)
UNUserNotificationCenter.current().add(request)
}

static func removeNotification(withIdentifiers identifiers: [String]) {
UNUserNotificationCenter.current().removePendingNotificationRequests(withIdentifiers: identifiers)
}
}

0 comments on commit 9acb24b

Please sign in to comment.