question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

I am working on a capacitor app for iOS and I am running into some issues and have some general questions:

My goal is to have an app that has a few custom native UIViewControllers to handle some native things. The code I want to create is using OpenCV, which is C++ so right now all my custom code is Objective-C since Swift doesn’t easily support C++ integration yet.

I have much of it working with Capacitor in general but now I am running into roadblocks due to my ignorance of how it all works in XCode. I have the native code in the “App” project

App (Project)
   App (Group)
      MyUIViewController.mm (and .h)
      Main.storyboard

and the Capacitor stuff in the “Pods” project

Pods (Project)
   Development Pods (some kind of group but I am unfamiliar with the symbol)
      Capacitor (Group)
         Plugins (Group)
            MyCustomPlugin.swift (and .m for bridging)

MyCustomPlugin.swift has the following code:

@objc(MyCustomPlugin)
public class MyCustomPlugin: CAPPlugin {
    
    @objc func capture(_ call: CAPPluginCall) {
        let value = call.getString("value") ?? ""   // left in for testing
        let storyboard = UIStoryboard(name: "Main", bundle: nil)
        let controller = storyboard.instantiateViewController(withIdentifier: "myUIViewController")
        DispatchQueue.main.async {
            self.bridge.viewController.present(controller, animated: true, completion: nil)
        }
        // left in for testing
        call.success([
            "value": value
        ])
    }
}

When I run this on my iPhone it all works. I have a button in an Angular Component and when I click it I get my UIViewController view. All the Objective-C code works and all the OpenCV magic also happens just fine. BTW - This is COOL AS HELL and I really like Capacitor.

Now I need to real return data back to Angular after a user does something in MyUIViewController. From my plugin (in the Pod project) I need to get a concrete handle to MyUIViewController (not just the Storyboard’s UIViewController interface). But the Pod project does not see MyUIViewController. If I try to import it in the plugin class I get “No such module”. I though maybe it was a Swift/Objective-C thing but I tried a dummy Swift class in the App project and the plugin still could not see it. I do not know how to share the UIViewControllers (and related classes) with the plugin.

I tried to copy the references of the classes I need from App to Pods in the same Plugin group as the MyCustomPlugin class and Xcode has no issue with the classes, but then Xcode complained about the OpenCV framework (which BTW I added to the Podfile with the ‘App’ target as the documentation recommends). I am guessing I can get everything working by adding the OpenCV framework to the ‘Pods’ target, but it feels like I am doing something wrong. So I want to reach out and find out the “correct” way to do this.

Thank you, Steve

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
mlynchcommented, May 1, 2018

Great issue and glad the native integration is working well!

The plugin is isolated to its own module, so unless you have dependencies in that plugin pointing to your custom native code, you won’t be able to access that code through static means. This is different from how Cordova worked where all plugin code was copied to your project, but that has other pitfalls.

However, you should be able to get that view controller dynamically using objective-c dynamism.

For example, try NSClassFromString to get MyUIViewController and instantiate it, probably can even replace the storyboard code with this: https://stackoverflow.com/a/32265287

Let me know how that goes! Closing as this is not a big but rather a conceptual question. Cheers

0reactions
ionitron-bot[bot]commented, Nov 11, 2022

Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Capacitor, please create a new issue and ensure the template is fully filled out.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Apple Support on the App Store
Apple Support gives you personalized access to solutions for all of your Apple products and services. Learn how to manage your subscriptions, reset...
Read more >
App Store - Official Apple Support
Get help with apps that you purchased or downloaded in the App Store that aren't made by Apple. Find contact information. Search for...
Read more >
Official Apple Support
Apple support is here to help. Learn more about popular topics and find resources that will help you with all of your Apple...
Read more >
Get tips on iPhone - Apple Support
See a collection of tips that help you get the most from iPhone. ... In the Tips app, you can learn how to...
Read more >
iPhone - Official Apple Support
Learn how to set up and use your iPhone. Find all the topics, resources, and contact options you need for iPhone.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found