Попытка использовать iOS обнаружение звукового паттерна и отправку сообщений во флаттер. Как Наблюдатель ответил бы на Flutter FlutterResult?
Я пытаюсь включить как можно больше кода, части комментариев выделяют вопрос.
@objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
let controller: FlutterViewController = window?.rootViewController as! FlutterViewController
let eventChannel = FlutterMethodChannel(name: "com.example/event",
binaryMessenger: controller.binaryMessenger)
var resultsObserver = ResultsObserver()
eventChannel.setMethodCallHandler({
(call: FlutterMethodCall, result: @escaping FlutterResult) -> Void in
...
analyzer = SNAudioStreamAnalyzer(...)
analyzer.add(request, withObserver: resultsObserver)
self.detectPattern(result: result)
})
}
private func detectPattern(result: FlutterResult) {
// this is how I would normally respond
result("found pattern")
}
}
class ResultsObserver: NSObject, SNResultsObserving {
func request(_ request: SNRequest, didProduce result: SNResult) {
guard let result = result as? SNClassificationResult,
let classification = result.classifications.first else {return }
let confidence = classification.confidence * 100.0
if confidence > 60 {
// how to pass this event to Flutter as FlutterResult?
}
}
}