Alarm 모델을 정의하여 알람에 필요한 정보를 담는다
struct Alarm {
var id: UUID
var time: Date
var isEnabled: Bool
var repeatDays: [Weekday] // 반복 요일
var label: String
}
CoreData로 저장
알람 리스트 화면 (UITableView or UICollectionView)
각 셀에는 알람 시간, 설명, 스위치
알람 추가 화면
UIDatePicker로 시간 설정
요일 선택 (반복 설정)
알람 라벨 설정
저장 버튼 → 알람 저장 및 알림 예약
셀에서 스위치 toggle → 모델의 isEnabled 값 변경
isEnabled == true → 알림 예약
isEnabled == false → 예약된 알림 제거
알림 권한
UNUserNotificationCenter.current().requestAuthorization(...)
알람 등록 시 UNNotificationRequest 생성
let content = UNMutableNotificationContent()
content.title = "알람"
content.body = label
content.sound = .default
let trigger = UNCalendarNotificationTrigger(dateMatching: components, repeats: true/false)
let request = UNNotificationRequest(identifier: alarm.id.uuidString, content: content, trigger: trigger)
UNUserNotificationCenter.current().add(request)
반복 요일 설정 시 요일마다 UNNotificationRequest 여러 개 등록
알람 삭제 또는 off 시
UNUserNotificationCenter.current().removePendingNotificationRequests(withIdentifiers: [alarm.id.uuidString])
UNNotificationContent에 .sound = .default ?? .named("custom.caf") 설정
백그라운드에서 시스템 알림으로 울리므로 앱이 실행 중일 필요 없음
iOS 알람 벨소리 설정 및 구현 분석
가장 간단한 방식은 iOS가 제공하는 기본 사운드를 재생하는 것
UNMutableNotificationContent에 .sound = .default 설정
앱 번들에 포함되어 있어야 함
caf, aiff, wav 형식만 지원
용량은 30초 미만이어야 함 (30초 초과 시 무음 처리)
사운드 파일 추가
식별(id)
시간(time)
반복 요일(repeatWeekdays)
레이블(label)
사운드(soundName)
스누즈(snoozeEnabled)
활성화(isEnabled)