사용자에게 알림을 보낼 때 사용
-> 권한이 있는 사용자에게만 가능
로컬 알림은 UNNotificationRequest 객체를 만들어 생성됩니다.
이 객체에는 알림의 컨텐츠 및 예약된 시간 등의 정보가 포함됩니다.
import UIKit
import UserNotifications
let center = UNUserNotificationCenter.current()
// 알림의 콘텐츠 설정
let content = UNMutableNotificationContent()
content.title = "알림 제목"
content.body = "알림 내용"
content.sound = UNNotificationSound.default
// 알림 발송 시각 설정 (5초 후)
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 5, repeats: false)
// 알림 요청 생성
let request = UNNotificationRequest(identifier: "testNotification", content: content, trigger: trigger)
// 알림을 스케줄링
center.add(request) { (error) in
if let error = error {
print("로컬 알림을 스케줄링하는 동안 오류 발생: \(error)")
}
}