iOS: Segues/unwind segues when using performSegue or present in Capcitor iOS plugin


So first of all, Capacitor is great. I’m really enjoying working with this.

Ive actually got two questions/issues regarding iOS Capacitor plugins that I hope someone here can help me with.

In my iOS Capacitor App I have an extension of the CAPBridgeViewController where I define variables and a “override func prepare” for segue function, as well as my custom Capacitor plugin that I use to send data from TypeScript on a button click.

My plugin is called from typescript in my Ionic app, which passes some data in the call. This all works great and within my plugin I am able to do further things with Swift.

I want to use performSegue inside DispatchQueue.main.async to send the user to a custom native view controller.

This works fine, but I cannot figure out how to access/modify the variables I’ve declared in my CAPBridgeViewController extension so that when the segue is performed they get passed through according to my “ovverride func prepare for” function.

To get around this, I’ve done the following inside of my .swift file for my Capacitor plugin

       let myVC : MyCustomViewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "MyCustomViewController") as! MyCustomViewController
    myVC.user = currentUser
    myVC.ticketNumber = ticketID

        self.bridge.viewController.present(myVC, animated: false)}

This works and the appropriate data gets to where it needs to be, but it is not ideal I think… because if my custom view controller already exists because of the storyboard, then I shouldn’t be instantiating a new one and then presenting that, right?

Anyway, using self.bridge.present gets my user to where they need to be and they can do what they need to do, but now I cannot get unwind segues to work.

In my CAPBridgeViewController extension I put:

    @IBAction func unwindToCAP(segue: UIStoryboardSegue) {}

and in my storyboard I control+drag the viewcontroller icon to the exit icon and select my unwindToCAP. Then I assign it an identifier of the same name “unwindToCAP”

Then I attach buttons in my custom view controller to a IBAction that exectutes

DispatchQueue.main.async{self.performSegue(withIdentifier: "unwindToCAP", sender: self)}

Unfortunately, this results in “yo” being printed to the console and nothing else, with no errors being shown.

So tl:dr I am at a loss here and I believe my issues result from the way I am navigating to my custom swift view controller from my Capacitor plugin.