UIApplicationDidEnterBackgroundNotification 被多次调用
我正在使用:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(stopTheDownload)
name:UIApplicationDidEnterBackgroundNotification
object:nil];
每当用户将应用程序切换到其他应用程序时停止下载。但是多次调用通知会导致不良行为(多次取消相同的下载......)
这正常吗?我认为一旦有人单击主页按钮,通知只会发送一次。但现在情况并非如此,有时它会给出 6 UIApplicationDidEnterBackgroundNotification ! (有时2次,有时4次,1次……)
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...)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能想查看何时添加观察者以及是否删除观察者。根据您实施观察者的方式,您可能会多次收到通知。
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.