@file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class) package eu.friedcutlet.yokan.app.profiles import kotlinx.coroutines.suspendCancellableCoroutine import platform.UserNotifications.* import kotlin.coroutines.resume import eu.friedcutlet.yokan.domain.ProfileId internal actual suspend fun cancelProfileBackgroundWork(id: ProfileId) { require(id != ProfileId.Default) // Fixed permitted BGTask identifiers are Default-owned. Extras have foreground work only. val center = UNUserNotificationCenter.currentNotificationCenter() val prefix = "yokan.profile.${id.value}." suspendCancellableCoroutine { continuation -> center.getDeliveredNotificationsWithCompletionHandler { values -> val ids = values.orEmpty().filterIsInstance().map { it.request.identifier }.filter { it.startsWith(prefix) } center.removeDeliveredNotificationsWithIdentifiers(ids) continuation.resume(Unit) } } suspendCancellableCoroutine { continuation -> center.getPendingNotificationRequestsWithCompletionHandler { values -> val ids = values.orEmpty().filterIsInstance().map { it.identifier }.filter { it.startsWith(prefix) } center.removePendingNotificationRequestsWithIdentifiers(ids) continuation.resume(Unit) } } }