使用 codesign 命令签名后,macOS 应用程序无法再通过 Internet 访问外部资源

macOS app can no longer access external resources over Internet after signing it with codesign command

我已经使用 Unity 构建了一个 macOS 应用程序包,我打算将其提交到 Mac App Store。我按照 Unity 文档 Delivering your application to the Mac App Store.

中提到的构建说明进行操作

我能够 运行 macOS 的构建命令并为我的应用程序获取 .app 包。我也可以启动它,而且 运行 绝对没问题。但是,在 运行 执行以下 codesign 命令后,该应用无法通过 Internet 访问任何资源。我的程序源代码中的 Internet 可达性模块报告无法访问 Internet。这是我运行ning:

codesign命令行
codesign -f --deep -s '3rd Party Mac Developer Application: DEVELOPER NAME' --entitlements "GAMENAME.entitlements" "/AppPath/GAMENAME.app"

所有外部资源都通过 HTTPS 访问。此外,项目的 Info.plist 文件添加了 NSAppTransportSecurityNSAllowsArbitraryLoads 键并设置为 true。 (这是 Unity 默认完成的。)

还值得注意的是,在 Unity 中构建 macOS 应用程序项目会生成 .app 包。包含的 Info.plist 文件预先配置了 NSAppTransportSecurityNSAllowsArbitraryLoads 键并设置为 true.

我尝试过保留和删除 NSAppTransportSecurityNSAllowsArbitraryLoads 键,但没有成功。我也试过在密钥下添加特定域,但没有成功。

我是运行所有软件都是当前最新版本,下面也一样:

  1. macOS 卡特琳娜 10.15.1

  2. Xcode 11.2.1

  3. 统一 2019.2.13

我的问题是:

我正在寻求暂时通过 Mac App Store 独家 分发应用程序。这将是一个付费应用程序(如果相关的话)。

Mac App Store 应用必须是 sandboxed。在沙盒环境中,需要额外的授权才能建立网络连接。

已列出权利 here。有关此特定问题,请参阅“启用网络访问”部分,其中显示:

Xcode’s Network checkboxes in the Summary tab of the target editor let you enable network access for your app.

To enable your app to connect to a server process running on another machine (or on the same machine), enable outgoing network connections.

To enable opening a network listening socket so that other computers can connect to your app, allow incoming network connections.

要允许传出网络连接,您需要添加 com.apple.security.network.client