iOS 16和iOS 15中的监听音量变化ExplicitVolumeChange通知最新方法SystemVolumeDidChangeNotification

一、老方案:

监听系统音量变化非常简单,只需要设置一个通知即可:AVSystemController_SystemVolumeDidChangeNotification

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(volumeChanged:)         
                                             name:@"AVSystemController_SystemVolumeDidChangeNotification"                                object:nil];

然后实现volumeChanged:方法

- (void)volumeChanged:(NSNotification *)notification
{   
    if (![[[notification userInfo] objectForKey:@"AVSystemController_AudioVolumeChangeReasonNotificationParameter"] isEqualToString:@"ExplicitVolumeChange"]) {
        return;
    }

猜你喜欢

转载自blog.csdn.net/xuexixiaoshizhe/article/details/128937941