问题描述
我开始将Flutter应用程序移植到 macos Desktop .用户界面开始正常.但是,应用程序一旦进行网络通话,就会立即失败,并显示连接失败(操作系统错误:不允许操作).
I started porting my Flutter app to macos Desktop. The UI started fine. However, as soon as the app makes a network call, it fails instantly with Connection failed (OS Error: Operation not permitted).
运行单线:
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的示例此处.
The macos build target comes from Google's sample here.
Flutter(频道主版,v1.9.8-pre.108)
推荐答案
您的macOS XCode项目缺少Internet权限,称为传出连接(客户端)".
Your macOS XCode project lacks Internet permission called "Outgoing Connections (Client)".
打开您的macOS Xcode项目-[root]/macos/Runner.xcworkspace
Open your macos xcode project - [root]/macos/Runner.xcworkspace
在项目导航器中单击运行器"-将显示常规设置.从标签栏中选择功能",然后勾选选项外向连接(客户端)" .
Click "Runner" in Project navigator - general settings will show up. Select "Capabilities" from tabbar and tick option "Outgoing Connections (Client)".
在XCode中重建应用程序并启动项目.
Rebuild your application inside XCode and launch the project.
这篇关于Flutter-macos构建目标上的http.get失败:连接失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!