override fun post()

in shared/src/iosMain/kotlin/org/jetbrains/kotlinconf/IOSLocalNotificationService.kt [37:79]


    override fun post(
        localNotificationId: LocalNotificationId,
        title: String,
        message: String,
        time: LocalDateTime?
    ) {
        logger.log(LOG_TAG) { "Posting: $time, $localNotificationId, $title, $message" }

        val content = UNMutableNotificationContent().apply {
            setTitle(title)
            setBody(message)
            setUserInfo(mapOf(LOCAL_NOTIFICATION_ID_KEY to localNotificationId.toString()))
        }
        val trigger = if (time != null) {
            val adjustedTime = timeProvider.getNotificationTime(time)
            UNCalendarNotificationTrigger.triggerWithDateMatchingComponents(
                dateComponents = NSDateComponents().apply {
                    year = adjustedTime.year.toLong()
                    month = adjustedTime.month.number.toLong()
                    day = adjustedTime.day.toLong()
                    hour = adjustedTime.hour.toLong()
                    minute = adjustedTime.minute.toLong()
                    second = adjustedTime.second.toLong()
                    val calendar = NSCalendar.currentCalendar
                    calendar.setTimeZone(EVENT_TIME_ZONE.toNSTimeZone())
                    this.calendar = calendar
                },
                repeats = false,
            )
        } else {
            null
        }
        val request = UNNotificationRequest.requestWithIdentifier(localNotificationId.toString(), content, trigger)
        notificationCenter.addNotificationRequest(request) { error: NSError? ->
            logger.log(LOG_TAG) {
                if (error == null) {
                    "Notification request completed successfully"
                } else {
                    "Notification request failed with error: $error"
                }
            }
        }
    }