Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Plugin with UIViewController

Can somebody explain to me the life-cycle of a Cordova iOS plugin?

Particularly, I have a plugin I am trying to develop which contains a UIView (and associated UIViewController).

How do I obtain the Cordova UIView from my extended CDVPlugin class, so I can add my plugin as a sub-view to it (is this how it works?).

I would like to temporarily show my UIView on top of my Cordova app, then dismiss it, returning to my JS/HTML app.

like image 564
keldar Avatar asked Jul 31 '15 16:07

keldar


2 Answers

If you want to present the whole UIViewController (full screen) over the cordova webview, you can do

[self.viewController presentViewController:yourViewController animated:YES completion:nil];

Examples:

Camera plugin

InAppBrowser plugin

If you want to add just a view over the cordova webview, you can do

[self.viewController.view addSubview:yourView];

Examples:

MapKit plugin

The diference is, that the first method present the whole view controller, full screen, the second method shows a view that can have the size and position you want, if you don't make it have the same size of the device screen the user will see your cordova webview under it

like image 164
jcesarmobile Avatar answered Oct 16 '22 13:10

jcesarmobile


Please refer the answer given by @jcesarmobile above

Plugin with UIViewController

For immature iOS developers like me who were not able to identify how to define yourViewController, follow below code

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UIViewController * yourViewController = [storyboard   instantiateViewControllerWithIdentifier:@"iController"] ;
[self.viewController presentViewController: yourViewController animated:YES completion:nil];

Where Main is the storyboard filename and iController is the viewController's storyboardIdentifier defined in the Main.Storyboard file

Please up vote the above answer given by @jcesarmobile

like image 27
Mohammed Irfan Avatar answered Oct 16 '22 13:10

Mohammed Irfan