Das ist die Flatterseite:
Code: Select all
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: Select all
//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)
}