简体   繁体   English

Xcode 在 flutter 项目中编写 ios 本机 swift 代码时给出错误类型“FlutterViewController”的值没有成员“binaryMessenger”

[英]Xcode giving error Value of type 'FlutterViewController' has no member 'binaryMessenger' when writing ios native swift code in flutter project

I made a flutter project with command我用命令做了一个 flutter 项目

flutter create -i swift myProject

then I changed the directory to myProject with cd myProject and ther I run pod setup.然后我使用 cd myProject 将目录更改为 myProject,然后运行 pod setup。 It run swiftly but when I added code to AppDeligate.swift in ios/Runner/Runner directory according to the tutorial here:它运行迅速,但是当我根据此处的教程将代码添加到 ios/Runner/Runner 目录中的 AppDeligate.swift 时:

https://flutter.dev/docs/development/platform-integration/platform-channels https://flutter.dev/docs/development/platform-integration/platform-channels

Here is my AppDeligate.swift:这是我的 AppDeligate.swift:

  @UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
  override func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: 
[UIApplicationLaunchOptionsKey: Any]?
  ) -> Bool {
    GeneratedPluginRegistrant.register(with: self)

let controller : FlutterViewController = window?.rootViewController as! FlutterViewController
  let batteryChannel = FlutterMethodChannel(name: "samples.flutter.dev/battery",
                                            binaryMessenger: controller.binaryMessenger)
  batteryChannel.setMethodCallHandler({
    (call: FlutterMethodCall, result: @escaping FlutterResult) -> Void in
    // Note: this method is invoked on the UI thread.
    // Handle battery messages.
      })

return super.application(application, didFinishLaunchingWithOptions: launchOptions)
  }
}

I am getting error "Value of type 'FlutterViewController' has no member 'binaryMessenger'"我收到错误消息“‘FlutterViewController’类型的值没有成员‘binaryMessenger’”

Am I missing something?我错过了什么吗?

Change this line更改此行

let batteryChannel = FlutterMethodChannel(name: "samples.flutter.dev/battery",
                                        binaryMessenger: controller.binaryMessenger)

To ->至 ->

let batteryChannel = FlutterMethodChannel(name: "samples.flutter.dev/battery",
                                        binaryMessenger: controller as! FlutterBinaryMessenger)

It was changed in latest flutter upgrade.在最新的 flutter 升级中进行了更改。

When using Flutter MACOS platform this will not help, you need to use this code:当使用 Flutter MACOS 平台时,这将无济于事,您需要使用以下代码:

let batteryChannel = FlutterMethodChannel(
      name: "samples.flutter.dev/battery",
      binaryMessenger: controller.engine.binaryMessenger
)

暂无
暂无

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

相关问题 类型的值没有成员值Swift 3给出错误 - Value of Type has no member Value Swift 3 giving Error “错误”类型的 xcode 8 值没有成员“用户信息” - xcode 8 value of type 'Error' has no member 'userinfo' 将项目从Swift 4转换为Swift 5时,“ ViewController”类型的值的错误没有成员“ keyboardDidShow(notification :)” - Error of Value of Type 'ViewController' has no member 'keyboardDidShow(notification:)' while converting project from swift 4 to swift 5 Xcode 8,Swift3。DataService类型的值没有成员“ Sign up” - Xcode 8, Swift 3. Value of type DataService has no member “Sign up” 从Swift1.2迁移到Swift 2时出错:“ UIViewController类型的值”没有成员'className' - Error when migrating from Swift1.2 to Swift 2 : “value of type ”UIViewController" has no member 'className' Xcode 10.2 iOS Swift (+ React Native) 项目编译错误 - Xcode 10.2 iOS Swift (+ React Native) project compilation error 'UITableView' 类型的值没有成员 'navigationController' swift iOS - Value of type 'UITableView' has no member 'navigationController' swift iOS iOS Swift:“NotificationCenter”类型的值没有成员“发布者” - iOS Swift: Value of type 'NotificationCenter' has no member 'publisher' IOS Dev 类型“AppDelegate”的值没有成员“managedObjectContext” Xcode 10 - IOS Dev Value of type 'AppDelegate' has no member 'managedObjectContext' Xcode 10 Swift 5 类型的值没有成员 - Swift 5 Value of type has no member
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM