You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Mac Silicon芯片上.NET MAUI调用libimobiledevice无法获取设备列表

在Mac Silicon设备上.NET MAUI调用idevice_id获取UDID失败的解决方法

问题现象

在Mac Silicon芯片设备上,终端或C#控制台程序执行idevice_id -l能正常获取iOS设备UDID列表,但在.NET MAUI应用中执行该二进制文件时,会出现两种错误:

  • 调用应用包内的idevice_id时,报错 ERROR: Unable to retrieve device list!
  • 使用系统路径/usr/bin/idevice_id时,报错 ERROR: Operation not permitted
    尝试过修改文件路径、将二进制文件放入应用内容包等操作,均无法解决问题。

问题原因

问题根源是MAUI应用默认启用了App Sandbox权限。App Sandbox会限制应用的系统访问范围,阻止应用与连接的iOS设备通信,导致idevice_id无法获取设备信息。

解决方法

关闭项目的App Sandbox权限:

  1. 找到项目中的Entitlements.plist文件
  2. 打开文件后,将App Sandbox对应的配置项设置为关闭(或直接移除<key>com.apple.security.app-sandbox</key>及其对应的<true/>节点)

相关代码示例

以下是调用idevice_id的C#代码(已修正语法错误):

private string GetInfo()
{
    string result = "";

    var command = $"{Path.Combine(Directory.GetCurrentDirectory(), "Contents/MonoBundle/idevice_id")} -l";
    
    try
    {
        Process process = new Process();
        process.StartInfo = new ProcessStartInfo
        {
            FileName = "/bin/bash",
            Arguments = $"-c \"{command}\"",
            UseShellExecute = false,
            RedirectStandardOutput = true,
            CreateNoWindow = true,
            WindowStyle = ProcessWindowStyle.Hidden
        };
        
        process.Start();
        string text = process.StandardOutput.ReadToEnd();
        if (!text.Contains("Unable"))
        {
            result = text;
        }

        process.WaitForExit();
    }
    catch (Exception ex)
    {
        Console.WriteLine(ex);
        Console.WriteLine(ex.Message);
    }
    
    Console.WriteLine($"Result: {result}");
    return result;
}

内容的提问来源于stack exchange,提问作者uhsnx

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.22 00:32:06