简体   繁体   English

颤振网络视图不适用于 ios 应用程序

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

I have created my first flutter module which is having a single web view in it.我已经创建了我的第一个 flutter 模块,它有一个单一的 web 视图。 its working fine when running the module independently or running the .ios/Runner project But when i integrate this module with my ios app and run the app then the web view is disappeared.它在独立运行模块或运行 .ios/Runner 项目时工作正常但是当我将此模块与我的 ios 应用程序集成并运行该应用程序时,Web 视图消失了。

dart file code :飞镖文件代码:

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))
          ],
        ));
  }
}

here is the code for app delegate i used:这是我使用的应用程序委托的代码:

lazy var flutterEngine = FlutterEngine()

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

        flutterEngine.run()
        
        return true
    }

Here is the code for iOS viewcontroller for navigation这是用于导航的 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)

the first output is for module/runner app.第一个输出用于模块/运行器应用程序。
2nd output is for my ios app.第二个输出用于我的 ios 应用程序。 这是模块/运行器项目输出

当我运行 ios 应用程序时,网络视图消失了

iOS

In order for plugin to work correctly, you need to add new key to ios/Runner/Info.plist为了使插件正常工作,您需要向 ios/Runner/Info.plist 添加新密钥

<key>NSAppTransportSecurity</key>

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

If your URL has some special character then you need to encode the URL like this,如果您的 URL 有一些特殊字符,那么您需要像这样对 URL 进行编码,

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 flutter 发布/生产应用程序查看 ios 日志 - flutter release/production app view ios logs Flutter App 在 Android 上运行流畅,但在 iOS 上无法运行 - Flutter App running smooth on Android but not working on iOS Flutter 应用程序无法在真正的 ios 设备上运行 - Flutter app not working on real ios device 在本机 iOS 应用程序中从 web 视图进行身份验证? - Authentication from web view in a native iOS app? 检查不是我的IOS的应用程序的Web视图 - Inspecting Web View of an app that's not mine IOS .blur()上的jQuery .hide()在iOS Web应用程序中不起作用 - jQuery .hide() on .blur() not working in iOS web app iOS Web 应用程序不能在主屏幕应用程序中离线工作,但可以在 Safari 中工作 - iOS web app not working offline in homescreen app, but working in Safari 来自 SMS 密码的 iOS 自动填充在 Flutter Web 上不起作用 - iOS Autofill from SMS passcodes not working on flutter web Google NotoSans 字体在 Flutter Web 应用程序中的 iOS 上无法正确显示 - Google NotoSans font not displaying correctly on iOS in flutter web app Flutter iOS 应用程序在模拟器中完美运行,但在真实设备中无法运行 - Flutter iOS app working perfect in simulator but not in real device
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM