봇이 메시지를 보내는 응용 프로그램을 작성 중입니다. 이러한 메시지는 로컬 알림으로 수신 될 수 있습니다.
문제는 :
보트가 단기간 내에 복수의 통지를 송신한다 (각 메시지 사이 일초), 통지 센터는 하나의 메시지를 표시한다. 내가 예상 할 때마다 알림 소리가 들리 겠지만, 나는 여전히 첫 번째 메시지 만 볼 것입니다.
관련 코드 : 코드 문제
func postUserNotification(content: String, delay: TimeInterval, withDictionary dictionary: [String:String] = [:]) {
let notificationContent = UNMutableNotificationContent()
notificationContent.body = content
notificationContent.userInfo = dictionary
notificationContent.categoryIdentifier = "message"
let dateAfterDelay = Date(timeIntervalSinceNow: delay)
let dateComponents = Calendar.current.dateComponents([.year,.month,.day,.hour,.minute,.second], from: dateAfterDelay)
let trigger = UNCalendarNotificationTrigger(dateMatching: dateComponents, repeats: false)
let identifier = "identifier" + "\(NotificationManager.incrementor)"
let localNotification = UNNotificationRequest(identifier: identifier, content: notificationContent, trigger: trigger)
UNUserNotificationCenter.current().add(localNotification){ (error : Error?) in
if let theError = error {
print("the error is \(theError.localizedDescription)")
}
}
}
Arnav가 언급했듯이 이것은 예상되는 기능이므로 이제 질문은 좋은 해결 방법은? – osebas15
문제는 앱이 비활성 상태 임에도 불구하고 앱에서 알림을 보내려고한다는 것입니다. 이 사실을 깨닫고 앱이 실제로 활성 상태를 잃기 전에 다가오는 모든 알림을 대기열에 올려 놓음으로써 해결되었습니다. – osebas15