0
알림을 설정할 때 지역 알림을 보내야하는 알림 앱을 개발하고 싶습니다. 여러 알림을 설정하는 경우에도 하나의 알림 만 트리거하는 코드를 개발했습니다. 7:30 PM, 7:31 PM, 7:32 PM에 미리 알림을 설정하면 알림은 오후 7시 32 분에만 표시됩니다.iOS - 여러 로컬 알림 일정 지정, UNCalenderNotificationTrigger
여기에 내 코드
func scheduleNotification(at date: Date) {
let calendar = Calendar(identifier: .gregorian)
let components = calendar.dateComponents(in: .current, from: date)
let newComponents = DateComponents(calendar: calendar, timeZone: .current, month: components.month, day: components.day, hour: components.hour, minute: components.minute)
let trigger = UNCalendarNotificationTrigger(dateMatching: newComponents, repeats: true)
let content = UNMutableNotificationContent()
content.title = "Reminder"
content.body = "To day is the last date for the payment of your card. Please make payment today."
content.sound = UNNotificationSound.default()
content.categoryIdentifier = "PaymentReminderIdentifier"
let request = UNNotificationRequest(identifier: "ReminderNotification", content: content, trigger: trigger)
UNUserNotificationCenter.current().delegate = self
//UNUserNotificationCenter.current().removeAllPendingNotificationRequests()
UNUserNotificationCenter.current().add(request) {(error) in
if let error = error {
print("Uh oh! We had an error: \(error)")
}
}
}
입니다 //
func notif() {
let selectedDate = fullDate
print("Selected date: \(selectedDate)")
let delegate = UIApplication.shared.delegate as? AppDelegate
delegate?.scheduleNotification(at: selectedDate!)
}
내가 알림을 만들 때마다 통지 시간을 제공하고자합니다. 이 문제를 해결하는 데 도움을줍니다. 고맙습니다 ...