簡體   English   中英

顫振網絡視圖不適用於 ios 應用程序

[英]flutter web view is not working with ios app

我已經創建了我的第一個 flutter 模塊,它有一個單一的 web 視圖。 它在獨立運行模塊或運行 .ios/Runner 項目時工作正常但是當我將此模塊與我的 ios 應用程序集成並運行該應用程序時,Web 視圖消失了。

飛鏢文件代碼:

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:webview_flutter/webview_flutter.dart';

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Material App',
      theme: ThemeData.light(),
      home: Home(),
    );
  }
}

// ignore: must_be_immutable
class Home extends StatelessWidget {
  String _url = "https://www.google.com";
  final _key = UniqueKey();
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
            title: Text("Web Viewwww"),
            leading: IconButton(
              icon: Icon(Icons.arrow_back),
              onPressed: () => SystemNavigator.pop(
                  animated: true) /*Navigator.pop(context, true)*/,
            )),
        body: Column(
          children: [
            Expanded(
                child: WebView(
                    key: _key,
                    javascriptMode: JavascriptMode.unrestricted,
                    initialUrl: _url))
          ],
        ));
  }
}

這是我使用的應用程序委托的代碼:

lazy var flutterEngine = FlutterEngine()

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

        flutterEngine.run()
        
        return true
    }

這是用於導航的 iOS 視圖控制器的代碼

let engin = (UIApplication.shared.delegate as! AppDelegate).flutterEngine
 let myflutterVC = FlutterViewController(engine: engin, nibName: nil, bundle: nil)
        myflutterVC.modalPresentationStyle = .fullScreen
        present(myflutterVC, animated: true, completion: nil)

第一個輸出用於模塊/運行器應用程序。
第二個輸出用於我的 ios 應用程序。 這是模塊/運行器項目輸出

當我運行 ios 應用程序時,網絡視圖消失了

iOS

為了使插件正常工作,您需要向 ios/Runner/Info.plist 添加新密鑰

<key>NSAppTransportSecurity</key>

<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
<key>NSAllowsArbitraryLoadsInWebContent</key>
<true/>

如果您的 URL 有一些特殊字符,那么您需要像這樣對 URL 進行編碼,

 WebView( initialUrl: Uri.encodeFull(yourUrl), ... )

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM