iOS Simulator crashes on microphone permission request
Please make sure you have added the correct entries to the Info.plist
file (for Flutter projects this file is located in the ios/Runner/
folder).
To access the microphone you will need to add the following lines in between the <dict>
tags:
<key>NSMicrophoneUsageDescription</key>
<string>this application needs access to the microphone</string>
More information can be found here.
And a complete example of an Info.plist
can be found here.
Comments
-
Corey Cole over 1 year
My environment:
- permission_handler 3.0.0
- Flutter v1.2.1
- OSX High Sierra 10.13.6
- Xcode version 10.1.
My app is crashing when I request the permission for microphone in the iOS simulator.
PermissionStatus mic = await PermissionHandler() .checkPermissionStatus(PermissionGroup.microphone); print('microphone permission? ${mic.toString()}'); try { if (mic != PermissionStatus.granted) { await PermissionHandler().requestPermissions([PermissionGroup.microphone]); } } catch (e) { print(e); }
No error is thrown or caught, but in the flutter debug console, I see:
flutter: microphone permission? PermissionStatus.unknown Lost connection to device.
This means that
checkPermissionStatus()
returnedunknown
. But then when I request the permission, the application crashes. I have not been able to try this on a real iPhone. Everything works perfectly on the Android simulator.I've seen there were some problems in Xcode 10.1 with the microphone:
- iOS Simulator would like to access microphone every time
- Repeated request for microphone permission on iOS Simulator
What I've tried
- Fresh build with
flutter clean
- Changing the simulator microphone input in Hardware > Audio Input
I could try to upgrade to Xcode 10.2, but I'd need to get mojave first. Trying to avoid that if possible as it might not even fix the issue. I can also try using a real iPhone device instead of the simulator. Would love to get the simulator not crashing, though.
Is anyone able to grant microphone permission in Xcode
10.1
/10.2
simulator usingpermission_handler: 3.0.0
? What about another flutter permission plugin?-
matt about 5 yearsI know nothing about Flutter, but I think you've answered your own question. There are many things that just don't work on the simulator, and this could very well be one of them.
-
Corey Cole about 5 years@matt but looking at the stack overflow questions I linked, it seems like people were at least able to grant microphone permission without the app crashing
-
matt about 5 yearsWell I’m suggesting maybe flutter changes the equation
-
czater about 5 yearsFor sure you can use a mic in a simulator (it will use mac mic). Try to click 2 times in home button (to invoke Siri) and check if Siri works correctly just to be sure that everything is ok with your mac. Maybe your mic is blocked or so.
-
Tejas Badani about 5 yearsYou will definitely find that your error lies in the info.plist file. Open runner.xcworkspace and navigate to the info.plist file and add permission for the microphone.
-
Corey Cole about 5 yearsYup! This was it. I added the
UIBackgroundModes->audio
, but not theNSMicrophoneUsageDescription
.