MethodChannelManager.swift 743 B

1234567891011121314151617181920212223242526272829303132
  1. //
  2. // MethodChannelManager.swift
  3. // Runner
  4. //
  5. // Created by Destiny on 2024/11/19.
  6. //
  7. import Flutter
  8. import UIKit
  9. class MethodChannelManager: NSObject {
  10. var channel: FlutterMethodChannel
  11. init(messager: FlutterBinaryMessenger) {
  12. channel = FlutterMethodChannel(name: "assistant_method_channel", binaryMessenger: messager)
  13. channel.setMethodCallHandler { (call , result) in
  14. print("接收到了来自Flutter发送的方法\(call.method)")
  15. result("我是原生返回给Flutter的消息")
  16. }
  17. }
  18. func sendMessage() {
  19. channel.invokeMethod("ios_method", arguments: "我是原生主动发送过来的") {(result) in
  20. print(result)
  21. }
  22. }
  23. }