Updated to Xcode 10.1 on Mojave and now my app always asks to use the microphone

♀尐吖头ヾ 提交于 2019-11-30 14:41:53

问题


I am running a AVAudioSession which I suspect is activating the microphone request, but I only use it for sounds and music. When running Xcode 10.1 Simulator on macOS Mojave, why does it activate a request to access the microphone? I haven't written a single line to even ask access to it. My app doesn't need access to it nor do I want it to. Here's the code to play the music:

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];

If I comment out the above code, I will no longer get a request for the microphone. But then I don't have any music.

Sample project: https://github.com/Coeur/StackOverflow53109911
(you need macOS Mojave to reproduce the issue)


回答1:


I also got this problem recently on an audiostreaming app that has been working ok for years without the microphone access popup. It happens when you try to get the AVAudioSession.

Update: Seems like Xcode 10.2 (beta 1) solves this by only asking the first time and then remembering your answer.

Update2: Xcode 10.2 is now out and only asks the first time.



来源:https://stackoverflow.com/questions/53109911/updated-to-xcode-10-1-on-mojave-and-now-my-app-always-asks-to-use-the-microphone

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!