3

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?

Corey Cole
  • 2,262
  • 1
  • 26
  • 43
  • I 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. – matt Apr 25 '19 at 23:14
  • @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 – Corey Cole Apr 25 '19 at 23:53
  • Well I’m suggesting maybe flutter changes the equation – matt Apr 26 '19 at 00:13
  • For 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. – czater Apr 26 '19 at 03:52
  • You 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. – Tejas Badani Apr 26 '19 at 11:10

1 Answers1

6

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.

ifconfig
  • 6,242
  • 7
  • 41
  • 65
Maurits van Beusekom
  • 5,579
  • 3
  • 21
  • 35