fix/macos-release-sandbox-network
main
macOS 发布版(Release)启动后界面提示「无法连接后端」。
Release.entitlements 启用了 App Sandbox(com.apple.security.app-sandbox),但未声明 com.apple.security.network.client。沙箱内进程向 127.0.0.1:17890 的本地后端发起出站 HTTP 请求时被内核拒绝(EPERM)。
Release.entitlements
com.apple.security.app-sandbox
com.apple.security.network.client
127.0.0.1:17890
Debug 配置(DebugProfile.entitlements)含 network.server,因此开发时正常,问题仅在打包 Release 后暴露。
DebugProfile.entitlements
network.server
复现:codesign -d --entitlements :- GC-UI.app 可看到签名中仅有 app-sandbox,无任何 network 权限。
codesign -d --entitlements :- GC-UI.app
app-sandbox
GC-UI/frontend/macos/Runner/Release.entitlements
com.apple.security.network.server
GC-UI/frontend/macos/Runner.xcodeproj/project.pbxproj
10.14
12.0
重新构建 Release 并启动 GC.app 后,lsof -nP -a -p <GC-UI PID> -iTCP 显示:
lsof -nP -a -p <GC-UI PID> -iTCP
GC-UI ... TCP 127.0.0.1:xxxxx->127.0.0.1:17890 (ESTABLISHED)
前端成功建立到后端的连接,界面正常加载,不再提示无法连接。
- Release.entitlements 增加 com.apple.security.network.client / network.server: 发布版启用 App Sandbox 但缺少 network.client 时,前端向 127.0.0.1 后端的 出站 HTTP 请求会被内核拒绝,表现为打开界面即提示“无法连接后端”。 - project.pbxproj 部署目标 10.14 -> 12.0,兼容 Xcode 27(最低支持 12.0)。
No dependencies set.
The note is not visible to the blocked user.
问题
macOS 发布版(Release)启动后界面提示「无法连接后端」。
根因
Release.entitlements启用了 App Sandbox(com.apple.security.app-sandbox),但未声明com.apple.security.network.client。沙箱内进程向127.0.0.1:17890的本地后端发起出站 HTTP 请求时被内核拒绝(EPERM)。Debug 配置(
DebugProfile.entitlements)含network.server,因此开发时正常,问题仅在打包 Release 后暴露。复现:
codesign -d --entitlements :- GC-UI.app可看到签名中仅有app-sandbox,无任何 network 权限。修改
GC-UI/frontend/macos/Runner/Release.entitlements:新增com.apple.security.network.client与com.apple.security.network.server。GC-UI/frontend/macos/Runner.xcodeproj/project.pbxproj:部署目标10.14→12.0,兼容 Xcode 27(最低支持 12.0)。验证
重新构建 Release 并启动 GC.app 后,
lsof -nP -a -p <GC-UI PID> -iTCP显示:前端成功建立到后端的连接,界面正常加载,不再提示无法连接。