Scheduling UserNotifications in MessageFilter app extension is throwing an error

I have a MessageFilter app extension embedded in my iOS app and it works great filtering out junk SMS messages.

I want to show a local notification whenever a message has moved to the junk folder and I'm trying to do it like so:

final class MessageFilterExtension: ILMessageFilterExtension {
    func handle(_ queryRequest: ILMessageFilterQueryRequest,
                context: ILMessageFilterExtensionContext,
                completion: @escaping (ILMessageFilterQueryResponse) -> Void) {

        let offlineAction = self.offlineAction(for: queryRequest)

        switch offlineAction {
        case .allow, .junk, .promotion, .transaction:
            let response = ILMessageFilterQueryResponse()
            response.action = offlineAction
            scheduleLocalNotification(for: keyword) /* -> Here */
            completion(response)
        @unknown default:
            break
        }
    }

    func scheduleLocalNotification(for keyword: Keyword) {
        let content = UNMutableNotificationContent()
        content.title = "Test"
        content.body = "Test2"
        content.categoryIdentifier = "FILTER_SMS_BLOCKED"
        
        let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 3, repeats: false)
        
        let request = UNNotificationRequest(identifier: UUID().uuidString,
                                            content: content,
                                            trigger: trigger)
        
        UNUserNotificationCenter.current().add(request) { [weak self] error in
            guard let self else { return }
            if let error {
                logger.log(level: .os, icon: "💥", "Error scheduling local notification: \(error)")
            }
        }
    }
}

But I am getting the following error:

🌐 💥 Error scheduling local notification: Error Domain=NSCocoaErrorDomain Code=4099 "The connection to service named com.apple.usernotifications.usernotificationservice was invalidated from this process." UserInfo={NSDebugDescription=The connection to service named com.apple.usernotifications.usernotificationservice was invalidated from this process.}

I have setup the Push Notifications entitlement in the main app and in this app extension, and also requested push notifications authorization from the user on the main app.

What am I missing here?

Thanks!

Hey @EpicSyntax, did you ever manage to find a workaround for this issue?

Scheduling UserNotifications in MessageFilter app extension is throwing an error
 
 
Q