by Guest » 11 Jan 2025, 06:47
Ich möchte Sirikit in meine Flatteranwendung integrieren. Daher muss ich einen MethodChannel für die Kommunikation zwischen Host und Client einrichten. Ich möchte, dass die iOS-Seite eine Flatterfunktion aufruft und diese Antwort Siris Antwort ist.
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);
}
Dann muss ich den methodChannel auf der iOS-Seite angeben:
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)
}
Ich bin kein iOS-Entwickler und habe daher keine Ahnung, wie ich das eigentlich machen soll. Das Problem besteht derzeit darin, dass die IntentHandler.swift-Datei keinen Zugriff auf die Methodenkanaldaten hat, da diese in einer anderen Datei deklariert wurden. Wie kann meine Intenthandler-Datei die Flattermethode aufrufen und mit Siri antworten?
Ich möchte Sirikit in meine Flatteranwendung integrieren. Daher muss ich einen MethodChannel für die Kommunikation zwischen Host und Client einrichten. Ich möchte, dass die iOS-Seite eine Flatterfunktion aufruft und diese Antwort Siris Antwort ist.
Das ist die Flatterseite:
[code]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]
Dann muss ich den methodChannel auf der iOS-Seite angeben:
[code]//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]
Ich bin kein iOS-Entwickler und habe daher keine Ahnung, wie ich das eigentlich machen soll. Das Problem besteht derzeit darin, dass die IntentHandler.swift-Datei keinen Zugriff auf die Methodenkanaldaten hat, da diese in einer anderen Datei deklariert wurden. Wie kann meine Intenthandler-Datei die Flattermethode aufrufen und mit Siri antworten?