jiuzhougege
V2EX  ›  Flutter

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

  •  
  •   jiuzhougege · Aug 17, 2024 · 2040 views
    This topic created in 652 days ago, the information mentioned may be changed or developed.
    用 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>
    whevether
        1
    whevether  
       Aug 19, 2024
    真机是正式打包还是调试开发模式。调试模式没问题。但是正式打包 ios 不管你是不是开了这个允许安全都无效。因为你这个是 app 允许 http ,而 ios 系统强制需要 https 会被 ios 屏蔽。
    jiuzhougege
        2
    jiuzhougege  
    OP
       Aug 19, 2024
    @whevether 解决了,网上搜的 18 年的一个文章,说是 ios 的一个 bug ,但是很少出现,需要在设置-蜂窝网络-修改下任意一个 app 的连接选项即可,试了后果然可以了
    jiuzhougege
        3
    jiuzhougege  
    OP
       Aug 19, 2024
    @whevether release 模式也可以 http ,生命 NSAppTransportSecurity 和 NSAllowsArbitraryLoads 即可
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2493 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 40ms · UTC 15:58 · PVG 23:58 · LAX 08:58 · JFK 11:58
    ♥ Do have faith in what you're doing.