我正在运行AVAudioSession,我怀疑它正在激活麦克风请求,但我只将它用于声音和音乐.在macOS Mojave上运行Xcode 10.1 Simulator时,为什么要激活访问麦克风的请求?我还没有写过一行甚至要求访问它.我的应用程序不需要访问它也不需要它.这是播放音乐的代码:
AVAudioSession *title = [AVAudioSession sharedInstance];
[title setCategory:AVAudioSessionCategoryAmbient error:nil];
[title setActive:YES error:nil];
//MUSIC
NSString *path = [[NSBundle mainBundle] pathForResource:@"music_nature" ofType:@"mp3"];
NSURL *url = [NSURL fileURLWithPath:path];
titleMusic = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:NULL];
titleMusic.numberOfLoops = -1;
[titleMusic setVolume:1.0];
[titleMusic play];
Run Code Online (Sandbox Code Playgroud)
如果我注释掉上面的代码,我将不再收到麦克风的请求.但后来我没有任何音乐.
示例项目:https://github.com/Coeur/StackOverflow53109911
(您需要macOS Mojave来重现该问题)