我用命令做了一个颤振项目
flutter create -i swift myProject
然后我使用 cd myProject 将目录更改为 myProject,然后运行 pod setup。它运行迅速,但是当我根据此处的教程将代码添加到 ios/Runner/Runner 目录中的 AppDeligate.swift 时:
https://flutter.dev/docs/development/platform-integration/platform-channels
这是我的 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)
}
}
我收到错误“'FlutterViewController' 类型的值没有成员 'binaryMessenger'”
我错过了什么吗?