Sunday, August 30, 2026
HomeiOS Developmentgoal c - 【IOS】Monitor quantity key, inflicting a number of calls

goal c – 【IOS】Monitor quantity key, inflicting a number of calls

[ad_1]

I wish to do some operations by clicking the amount button. I can do that within the following methods

 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(volumeChangeNotification:)title:@"SystemVolumeDidChange" object:nil];

 - (void)volumeChangeNotification:(NSNotification *)notification {
  //do one thing
 }

However I discovered a puzzling phenomenon. Click on the amount key as soon as, and the monitoring occasion will probably be referred to as twice. I attempt to delete the listener on the finish of the listener perform ,like this

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(volumeChangeNotification:)title:@"SystemVolumeDidChange" object:nil];

- (void)volumeChangeNotification:(NSNotification *)notification {
//do one thing
[[NSNotificationCenter defaultCenter] removeObserver:self title:@"SystemVolumeDidChange" object:nil];
}

Then I activate the monitor after 1 second, however it additionally would not work. What ought to I do?thanks verymuch

[ad_2]

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments