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
}
}
--
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)
}
}