iOS仿真器因麦克风许可请求而崩溃

时间:2019-04-25 22:38:22

标签: ios xcode flutter ios-simulator microphone

我的环境:

  • permission_handler 3.0.0
  • Flutter v1.2.1
  • OSX High Sierra 10.13.6
  • Xcode版本10.1。

在iOS模拟器中请求麦克风许可时,我的应用程序崩溃了。

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);
}

没有引发或捕获任何错误,但是在Flutter调试控制台中,我看到了:

flutter: microphone permission? PermissionStatus.unknown
Lost connection to device.

这意味着checkPermissionStatus()返回了unknown。但是,当我请求许可时,应用程序崩溃。我无法在真正的iPhone上尝试此操作。一切都能在Android模拟器上完美运行。

我已经看到Xcode 10.1中的麦克风存在一些问题:

我尝试过的事情

  • 使用flutter clean的新版本
  • 在“硬件”>“音频输入”中更改模拟器的麦克风输入

我可以尝试升级到Xcode 10.2,但是我需要先获得莫哈韦沙漠。尽可能避免这种情况,因为它甚至可能无法解决问题。我也可以尝试使用真实的iPhone设备代替模拟器。不过,希望模拟器不会崩溃。

有人能够使用10.1在Xcode 10.2 / permission_handler: 3.0.0模拟器中授予麦克风权限吗?另一个flutter权限插件呢?

1 个答案:

答案 0 :(得分:2)

请确保已将正确的条目添加到Info.plist文件中(对于Flutter项目,此文件位于ios/Runner/文件夹中)。

要访问麦克风,您需要在<dict>标签之间添加以下行:

<key>NSMicrophoneUsageDescription</key>
<string>this application needs access to the microphone</string>

可以找到更多信息here.

here.可以找到Info.plist的完整示例