我已经用xcode(swift 4+)创建了一个可执行文件。我在项目(.plist文件)中添加了麦克风权限,并且我还要求运行时提供权限:这是代码:
switch AVCaptureDevice.authorizationStatus(for: .audio) {
case .authorized:
audioStarter.staticMode()
case .notDetermined:
AVCaptureDevice.requestAccess(for: .audio) { granted in
if granted {
print("Permission granted")
audioStarter.staticMode()
}
}
case .denied:
print("Permission denied")
exit(0)
case .restricted:
print("This user cannot access microphone")
exit(0)
}
如果我通过终端运行该可执行文件,它将运行良好(它显示了麦克风权限弹出窗口,并且运行良好)。但是,当我从Java Process运行此exec文件时,它没有显示访问麦克风的权限,因此该exec文件不起作用。这是Java中的示例代码:
String cmd = getBinPath() + "./audio_service -r";
try {
final Process p = Runtime.getRuntime().exec(cmd);
Scanner scanner = new Scanner(p.getInputStream());
while (scanner.hasNextLine()) {
String response = scanner.nextLine ();
System.out.println(response);
}
}
catch (Exception e) {
e.printStackTrace();
}