-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
알람 사운드를 설정할 수 있는 기능을 구현합니다.
- Loading branch information
Showing
59 changed files
with
1,031 additions
and
88 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
Multimer/Multimer/Data/Service/UserNotificationCenterService.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.