Search code examples
iosxcodeflutterios-simulatormicrophone

iOS Simulator crashes on microphone permission request


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() returned unknown. 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:

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 using permission_handler: 3.0.0? What about another flutter permission plugin?


Solution

  • 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.