The resource could not be loaded because the App Transport Security policy requires the use of a secure connection.


Flutter 使用 webview 訪問 “http://localhost:8080"時報錯,此錯誤應為 iOS11 禁止本地http的訪問。

解決方法:
在 `ios/Runner/Info.plist' 文件中添加

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsArbitraryLoads</key>
    <true />
    <key>NSAllowsLocalNetworking</key>
    <true />
    <key>NSExceptionDomains</key>
    <dict>
        <key>localhost</key>
        <dict>
            <key>NSExceptionAllowsInsecureHTTPLoads</key>
            <true />
            <key>NSExceptionRequiresForwardSecrecy</key>
            <false />
            <key>NSIncludesSubdomains</key>
            <true />
            <!-- Optional: Specify minimum TLS version -->
            <key>NSTemporaryExceptionMinimumTLSVersion</key>
            <string>TLSv1.1</string>
            <key>NSRequiresCertificateTransparency</key>
            <false />
        </dict>
    </dict>
</dict>

需要注意的是:此段代碼必須放在 plist 里面。

<plist version="1.0">
	<dict>
            <!-- 上面那段代碼放這 -->
        </dict>
</plist>

保存好文件,執行 flutter clean ,再重新運行即可。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM