flutter 开发的 APP 安装到真机接口请求异常

33 天前
 jiuzhougege
用 dio 请求后端接口

在模拟器一切正常,到真机提示如下:
DioExceptionType.connectionError The connection errored:Connection failed This indicates an error whichmost likely cannot be solved by the library.

是 dio 的问题吗?接口是 http://ip:port 的形式


已经在 info.plist 里申明了 http 放行
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
740 次点击
所在节点    Flutter
3 条回复
whevether
31 天前
真机是正式打包还是调试开发模式。调试模式没问题。但是正式打包 ios 不管你是不是开了这个允许安全都无效。因为你这个是 app 允许 http ,而 ios 系统强制需要 https 会被 ios 屏蔽。
jiuzhougege
31 天前
@whevether 解决了,网上搜的 18 年的一个文章,说是 ios 的一个 bug ,但是很少出现,需要在设置-蜂窝网络-修改下任意一个 app 的连接选项即可,试了后果然可以了
jiuzhougege
31 天前
@whevether release 模式也可以 http ,生命 NSAppTransportSecurity 和 NSAllowsArbitraryLoads 即可

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/1065801

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX