AVAudioSessionRouteChangeNotification 不断被调用

AVAudioSessionRouteChangeNotification keeps getting called

我正在使用 AVAudioSession 获取有关路线更改的信息 -

[[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(currentRouteChanged:)
                                                 name:AVAudioSessionRouteChangeNotification object:nil];

问题是关闭当前会话后 -

AVAudioSession *audioSession = [AVAudioSession sharedInstance];
    // close down our current session
    [audioSession setActive:NO error:nil];

仍在调用通知。

目前我正在使用 -

[[NSNotificationCenter defaultCenter] removeObserver:self];

停止呼叫,但它不正确。如果没有会话,为什么会调用此通知?

是否有 "stronger" 方法来终止音频会话而不是 -

[audioSession setActive:NO error:nil];

接到电话会收到此通知吗?

谢谢

If there is no session

总是一个音频会话。它是一个共享单例,就像应用程序、通知中心或用户默认值一样。它的存在与它的激活无关。音频会话从您的应用程序启动的那一刻起一直存在到它被杀死的那一刻。正如 docs 所说:

Upon launch, your app automatically gets a singleton audio session

不存在“关闭当前会话”之类的东西。 您取消注册不再需要的通知的想法是正确的。或者在他们到达时忽略他们。