我想将 Sirikit 集成到我的颤振应用程序中。因此,我必须建立一个MethodChannel用于主机和客户端之间的通信。我希望 iOS 端调用一个颤振函数,该响应是 Siris 的答案。这是颤振的一面:
void nativeFunc() {
const platform = const MethodChannel("flutter.siri");
Future<dynamic> _handleMethod(MethodCall call) async {
if (call.method == "message") {
return api_request("Physics", call.arguments, 50);
}
}
platform.setMethodCallHandler(_handleMethod);
}
然后我必须在iOS端指定methodChannel:
//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)
}
我不是 Ios 开发人员,所以我不知道如何实际执行此操作。现在的问题是IntentHandler.swift -File无权访问方法通道数据,因为它是在另一个文件中声明的。我的 Intenthandler 文件如何调用颤振方法并用 Siri 响应?