Implement UNUserNotificationCenterDelegate in iOS app using Swift6

I've got a problem with compatibility with Swift6 in iOS app that I have no idea how to sort it out.

That is an extract from my main app file

@MainActor
@main struct LangpadApp: App {
    ...
    @State private var notificationDataProvider = NotificationDataProvider()
    @UIApplicationDelegateAdaptor(NotificationServiceDelegate.self) var notificationServiceDelegate

    var body: some Scene {
        WindowGroup {
            TabView(selection: $tabSelection) {
                ...
            }
            .onChange(of: notificationDataProvider.dateId) { oldValue, newValue in
                if !notificationDataProvider.dateId.isEmpty {
                    tabSelection = 4
                }
            }
        }
    }

    init() {
        notificationServiceDelegate.notificationDataProvider = notificationDataProvider
    }
}

and the following code shows other classes

@MainActor
final class NotificationServiceDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate
{
    var notificationDataProvider: NotificationDataProvider?

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
        UNUserNotificationCenter.current().delegate = self
        return true
    }

    func setDateId(dateId: String) {
        if let notificationDataProvider = notificationDataProvider {
            notificationDataProvider.dateId = dateId
        }
    }

    nonisolated func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse) async {
        // After user pressed notification
        let content = response.notification.request.content
        if let dateId = content.userInfo["dateId"] as? String {
            await MainActor.run {
                setDateId(dateId: dateId)
            }
        }
    }

    nonisolated func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification) async -> UNNotificationPresentationOptions {
        // Before notification is to be shown
        return [.sound, .badge, .banner, .list]
    }
}

@Observable
final public class NotificationDataProvider : Sendable {
    public var dateId = ""
}

I have set Strict Concurrency Checking to 'Complete.' The issue I'm facing is related to the delegate class method, which is invoked after the user presses the notification.

Current state causes crash after pressing notification. If I remove "nonisolated" keyword it works fine but I get the following warning

Non-sendable type 'UNNotificationResponse' in parameter of the protocol requirement satisfied by main actor-isolated instance method 'userNotificationCenter(_:didReceive:)' cannot cross actor boundary; this is an error in the Swift 6 language mode

I have no idea how to make it Swift6 compatible. Does anyone have any clues?

Implement UNUserNotificationCenterDelegate in iOS app using Swift6
 
 
Q