xfze
xfze

Reputation: 785

UIApplicationDidEnterBackgroundNotification called multiple times

I'm using:

[[NSNotificationCenter defaultCenter] addObserver:self
                                      selector:@selector(stopTheDownload)
                                          name:UIApplicationDidEnterBackgroundNotification 
                                        object:nil];

to stop a download whenever the user switches the app to something else. But the notification is called many times leading to bad behavior (canceling the same download multiple times...)

is this normal? I would think that once someone clicked the Home Button the Notification would be sent only one time. But it's not the case right now, some times it gives 6 UIApplicationDidEnterBackgroundNotification ! (sometimes 2, sometimes 4, 1 a couple of times...)

Upvotes: 3

Views: 2483

Answers (1)

Reed Olsen
Reed Olsen

Reputation: 9169

You may want to look to see when you're adding the observer, and if you're ever removing the observer. Depending on how you've implemented your observers, you could be getting the notification multiple times.

Upvotes: 4

Related Questions