Wie integriere ich Siri mit MethodChannels in Flutter?IOS

Programmierung für iOS
Guest
 Wie integriere ich Siri mit MethodChannels in Flutter?

Post by Guest »

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?

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post