내 iOS 앱에서 이벤트 시작 15 분 전에 사용자에게 알리는 localNotification
을 만들려고합니다. 그러나 나는 붙어있다. 데이터를 저장하기 위해 CoreData
을 사용하고 있습니다. 내가 만들 수있는 Appointment
개체가 있습니다. date
특성은 Appointment
개체와 연결됩니다. 나는 정말로 그것에 매달렸다. timeInterval
및 나머지 알림 프로세스를 설정하는 방법을 모르겠습니다.CoreData 속성을 사용하여 UILocalNotifications 만들기
Appointment
이 생성 될 때부터 시작하기 15 분 전에 timeInterval
을 설정하는 방법을 모르겠습니다.
여기 내 코드의 일부입니다 :
func scheduleNotifications() {
let content = UNMutableNotificationContent()
guard let client = client, let name = client.name, let formula = formula, let date = formula.date else { return }
content.title = "BookMe"
content.subtitle = ""
content.body = "Your appointment with \(name) will begin soon."
content.badge = 1
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: ??, repeats: false)
편집 : 이것은 내가 가지고 있지만 아무것도 발사되지 않은 것입니다. 나는 당신이 그 이전에 알림 15 분 발사 할 수 있도록 지금 15 분 일부 날짜 이전 사이의 시간 간격을 찾기 위해 찾고 그것을 이해로서
let date = formula.date
let fireDate = Calendar.current.date(byAdding: DateComponents(minute: -15), to: date as Date)
guard let timeInterval = fireDate?.timeIntervalSince(Date()) else { return }
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: timeInterval, repeats: false)
let request = UNNotificationRequest(identifier: self.timerUserNotificationIdentifier, content: content, trigger: trigger)
UNUserNotificationCenter.current().add(request, withCompletionHandler: nil)
날짜를 작성하는 데 15 분짜리 만드는 방법을 묻는 중입니까? – Abizern
@Abizern 본질적으로 그렇습니다 –