【 ios】监视卷键,导致多个调用
我想通过单击“音量”按钮来进行一些操作。我可以通过以下方式做到这一点
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(volumeChangeNotification:)name:@"SystemVolumeDidChange" object:nil];
- (void)volumeChangeNotification:(NSNotification *)notification {
//do something
}
,但我发现了一个令人困惑的现象。单击卷键一次,监视事件将被调用两次。我尝试在侦听器函数末尾删除侦听器,这样
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(volumeChangeNotification:)name:@"SystemVolumeDidChange" object:nil];
- (void)volumeChangeNotification:(NSNotification *)notification {
//do something
[[NSNotificationCenter defaultCenter] removeObserver:self name:@"SystemVolumeDidChange" object:nil];
}
,我在1秒钟后打开监视器,但这也行不通。我该怎么办?非常感谢
I want to do some operations by clicking the volume button. I can do this in the following ways
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(volumeChangeNotification:)name:@"SystemVolumeDidChange" object:nil];
- (void)volumeChangeNotification:(NSNotification *)notification {
//do something
}
But I found a puzzling phenomenon. Click the volume key once, and the monitoring event will be called twice. I try to delete the listener at the end of the listener function ,like this
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(volumeChangeNotification:)name:@"SystemVolumeDidChange" object:nil];
- (void)volumeChangeNotification:(NSNotification *)notification {
//do something
[[NSNotificationCenter defaultCenter] removeObserver:self name:@"SystemVolumeDidChange" object:nil];
}
Then I turn on the monitor after 1 second, but it also doesn't work. What should I do?thanks verymuch
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论