How to integrate FlutterPlatformView and INUIAddVoiceShortcutButtonDelegate?

Viewed 8

I create a flutter app and need to add Siri button in my flutter app now, so I have to use FlutterPlatformView to host native iOS view. Unfortunately, I am not familiar with native iOS code....so I still can't figure out what is problem right now.

I have already successfully run the FlutterPlatformView without "INUIAddVoiceShortcutButtonDelegate", but when I add the extension of INUIAddVoiceShortcutButtonDelegate, I got error in "present function"(like the image below).

Thanks a lot if anyone can give me a hint!

enter image description here

import UIKit
import IntentsUI
import Flutter

class AddSiriView:NSObject,FlutterPlatformView{

let frame: CGRect
let viewId:Int64
private var _view: UIView

init(_ frame:CGRect,viewId:Int64,args:Any?){
    self.frame = frame
    self.viewId = viewId
    _view = UIView()
    super.init()
    addSiriButton(to: _view)
// iOS views can be added here
}

public func view() -> UIView {
    return _view
}

func addSiriButton(to view: UIView) {
        let button = INUIAddVoiceShortcutButton(style: .whiteOutline)
        
    button.shortcut = INShortcut(intent: intent )
        button.delegate = self
        
        button.translatesAutoresizingMaskIntoConstraints = false
        
        view.addSubview(button)
        view.centerXAnchor.constraint(equalTo: button.centerXAnchor).isActive = true
        view.centerYAnchor.constraint(equalTo: button.centerYAnchor).isActive = true
    }
}

extension AddSiriView: INUIAddVoiceShortcutButtonDelegate {
    func present(_ addVoiceShortcutViewController: INUIAddVoiceShortcutViewController, for addVoiceShortcutButton: INUIAddVoiceShortcutButton) {
    addVoiceShortcutViewController.delegate = self
    addVoiceShortcutViewController.modalPresentationStyle = .formSheet
    ==============I always get error here===============================
    present(addVoiceShortcutViewController, animated: true, completion: nil)
}

func present(_ editVoiceShortcutViewController: INUIEditVoiceShortcutViewController, for addVoiceShortcutButton: INUIAddVoiceShortcutButton) {
    editVoiceShortcutViewController.delegate = self
    editVoiceShortcutViewController.modalPresentationStyle = .formSheet
    ==============I always get error here===============================
    present(editVoiceShortcutViewController, animated: true, completion: nil)
    }
}

extension AddSiriView: INUIAddVoiceShortcutViewControllerDelegate {
func addVoiceShortcutViewController(_ controller: INUIAddVoiceShortcutViewController,         didFinishWith voiceShortcut: INVoiceShortcut?, error: Error?) {
    controller.dismiss(animated: true, completion: nil)
}

func addVoiceShortcutViewControllerDidCancel(_ controller:     INUIAddVoiceShortcutViewController) {
    controller.dismiss(animated: true, completion: nil)
    }
}

extension AddSiriView: INUIEditVoiceShortcutViewControllerDelegate {
func editVoiceShortcutViewController(_ controller: INUIEditVoiceShortcutViewController, didUpdate voiceShortcut: INVoiceShortcut?, error: Error?) {
    controller.dismiss(animated: true, completion: nil)
}

func editVoiceShortcutViewController(_ controller:     INUIEditVoiceShortcutViewController, didDeleteVoiceShortcutWithIdentifier     deletedVoiceShortcutIdentifier: UUID) {
    controller.dismiss(animated: true, completion: nil)
}

func editVoiceShortcutViewControllerDidCancel(_ controller: INUIEditVoiceShortcutViewController) {
    controller.dismiss(animated: true, completion: nil)
    }
}

extension AddSiriView {
    public var intent: ConductIntent {
    let testIntent = ConductIntent()
    testIntent.action = "my test intent"
    return testIntent
    }
}

public class AddSiriViewFactory : NSObject,FlutterPlatformViewFactory{
public func create(
    withFrame frame:CGRect,
    viewIdentifier viewId:Int64,
    arguments args: Any?
) -> FlutterPlatformView{
    return AddSiriView(frame,viewId: viewId,args: args)
    }
}
0 Answers
Related