我开始将我的 Flutter 应用程序移植到macOS 桌面。用户界面开始很好。但是,一旦应用程序进行网络调用,它就会立即失败,并显示连接失败(操作系统错误:不允许操作).
运行单行:
final response = await http.get('https://jsonplaceholder.typicode.com/posts/1');
失败并显示:
Unhandled Exception: SocketException: Connection failed (OS Error:
Operation not permitted, errno = 1),
address = jsonplaceholder.typicode.com, port = 443
#0 IOClient.send (package:http/src/io_client.dart:33:23)
macos 构建目标来自 Google 的示例here https://github.com/google/flutter-desktop-embedding.
Flutter(通道大师,v1.9.8-pre.108)
根据我对其他答案的评论,你应该not为此,请使用 Xcode 功能 UI。它无法正确处理 Flutter 项目中的两个单独的权利文件。
您需要添加:
<key>com.apple.security.network.client</key>
<true/>
to macos/Runner/DebugProfile.entitlements
and macos/Runner/Release.entitlements
.
这是有记录的here https://docs.flutter.dev/development/platform-integration/macos/building#setting-up-entitlements and here https://developer.apple.com/documentation/bundleresources/entitlements/com_apple_security_network_client.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)