Open NavigationLink from Local Notification in NavigationStack iOS17

25 Views Asked by At

The Notification provides the uuid corresponding to the Item saved in SwiftData.

Goal is to open the correct DetailItem View when I tap the notification. How can I achieve this?

@Model
final class Item {
    @Attribute(.unique) var uuid: UUID
     ...
}

--

extension LocalNotificationManager: UNUserNotificationCenterDelegate {


func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse) async {
    
    guard let userInfo = response.notification.request.content.userInfo["uuid"] as? Data else {
        print("No data found in notification userInfo")
        return
    }
    **What shall I do here ?**
    
}

--

struct ItemList: View {
@Query var items: [Item]
@State private var path = NavigationPath()

var body: some View {
    NavigationStack(path: $path) {
                ForEach(Array(items.enumerated()), id: \.element.id) { index, item in
                    NavigationLink(value: item) {
                        ItemButton(item: item, index: index)
                        }
                    }
                }
        }.navigationDestination(for: Item.self) { item in
            DetailItem(item: item)
        }
 }
0

There are 0 best solutions below