Я хочу интегрировать Sirikit в мое приложение Flutter. Поэтому я должен установить MethodChannel для связи между хостом и клиентом. Я хочу, чтобы iOS-сторона вызвала функцию трепетала, и этот ответ будет ответом на Siris.
Это трепетание: < /p>
void nativeFunc() {
const platform = const MethodChannel("flutter.siri");
Future _handleMethod(MethodCall call) async {
if (call.method == "message") {
return api_request("Physics", call.arguments, 50);
}
}
platform.setMethodCallHandler(_handleMethod);
}
< /code>
Тогда я должен указать методханал на стороне iOS: < /p>
//AppDelegate.swift
import UIKit
import Flutter
@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
let controller : FlutterViewController = window?.rootViewController as! FlutterViewController
let methodChannel = FlutterMethodChannel(name:"flutter.siri")
GeneratedPluginRegistrant.register(with: self)
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
}
//IntentHandler.swift
func handle(intent: INSendMessageIntent, completion: @escaping (INSendMessageIntentResponse) -> Void) {
// Implement your application logic to send a message here.
let userActivity = NSUserActivity(activityType: NSStringFromClass(INSendMessageIntent.self))
let response = methodChannel.invokeMethod()//this should invoke the MethodChannel-function from Flutter
completion(response)
}
< /code>
Я не iOS-разработчик, поэтому я понятия не имею, как это сделать. Прямо сейчас проблема в том, что intenthandler.swift -file не имеет доступа к данным канала метода, поскольку он был объявлен в другом файле. Как мой Intenthandler-File может вызвать метод трепета и ответить Siri?
Подробнее здесь: https://stackoverflow.com/questions/678 ... odchannels