Sha*_*ank 2 native ios swift flutter
我用命令做了一个flutter项目
flutter create -i swift myProject
Run Code Online (Sandbox Code Playgroud)
然后我使用 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)
}
}
Run Code Online (Sandbox Code Playgroud)
我收到错误“‘FlutterViewController’类型的值没有成员‘binaryMessenger’”
我错过了什么吗?
改变这一行
let batteryChannel = FlutterMethodChannel(name: "samples.flutter.dev/battery",
binaryMessenger: controller.binaryMessenger)
Run Code Online (Sandbox Code Playgroud)
至 ->
let batteryChannel = FlutterMethodChannel(name: "samples.flutter.dev/battery",
binaryMessenger: controller as! FlutterBinaryMessenger)
Run Code Online (Sandbox Code Playgroud)
它在最新的 flutter 升级中发生了变化。
| 归档时间: |
|
| 查看次数: |
3174 次 |
| 最近记录: |