Navigating/showing a view after a user taps on a local notification

The behavior I'm trying to implement is when a user taps a local notification, I want to show a bottom sheet in the Home screen with more information regarding that notification.

I've followed the steps here to set up UNUserNotificationCenterDelegate so I can listen to notification completions in AppDelegate.

However, I'm not sure how to relay this information to a Store to trigger a state change. I can save a flag in UserDefaults and set a variable in HomeState to it but that won't trigger a state change (so the Home view will display the previous state without the updated value from UserDefaults so the sheet won't show).

Is there a way to send an action when I receive the notification completion from AppDelegate, or is there a way to trigger a state refresh when a non-state object is updated?

I'm open to other ways to go about this as well.


You can have your AppDelegate send an action to a view store:

let viewStore = ViewStore(store)

That would mean I would have to keep an instance of store in the AppDelegate which we're not doing so far. We're also using SceneDelegate and instantiating our main Store in there. Would doing this cause any issues when multiple scenes are involved?

It's a good idea to hold onto store at the entry point of your application so that you can feed it any lifecycle data it needs (like notifications), so if possible you could instantiate it in your app delegate and then access that store from your scene delegate. I don't think there would be any problems with multiple scenes, but if you encounter any issues please let us know!

1 Like

Thanks, I'll try it out!

Terms of Service

Privacy Policy

Cookie Policy