Stefan
Stefan

Reputation: 1357

Is there a way to buffer NSNotifications until the observer is ready?

One part of my program sends NSNotifications in irregular intervals. First some messages regarding the initial setup, then stuff triggered by GPS. The view controller that should observe those notifications takes some time to fire up and therefore usually misses the first few of them, though the addObserver: stuff is in viewDidLoad. So, is there a way for the view controller to get the messages it missed?

I am aware that I could send the whole message history with every notification, but still it would take until the next trigger event until anything is sent, and that would be too long.

Is there a standard approach to this, am I missing something?

Upvotes: 0

Views: 70

Answers (1)

Rick van der Linde
Rick van der Linde

Reputation: 2591

Create some NSObject where you store the messages. Then if the view that needs to listen to the notifications is loaded, check for any messages stored in the NSObject (so you won't need to wait for a new triggered message).

You are not missing something, you just need to change the way you handle the data a bit and it'll work perfectly :)

Upvotes: 1

Related Questions