带有 UIViewController 的插件

Plugin with UIViewController

有人可以向我解释 Cordova iOS 插件的生命周期吗?

特别是,我有一个正在尝试开发的插件,其中包含一个 UIView(以及关联的 UIViewController)。

如何从我的扩展 CDVPlugin class 中获取 Cordova UIView,以便我可以将我的插件添加为它的子视图(这是它的工作原理吗? ).

我想暂时在我的 Cordova 应用程序顶部显示我的 UIView,然后关闭它,返回到我的 JS/HTML 应用程序。

如果你想在 cordova webview 上呈现整个 UIViewController(全屏),你可以这样做

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

示例:

Camera plugin

InAppBrowser plugin

如果你只想在 cordova webview 上添加一个视图,你可以这样做

[self.viewController.view addSubview:yourView];

示例:

MapKit plugin

不同之处在于,第一种方法显示整个视图控制器,全屏,第二种方法显示可以具有您想要的大小和位置的视图,如果您不使其具有相同的大小用户将在其下方看到您的 cordova webview 的设备屏幕

请参考上面@jcesarmobile给出的回答

对于像我这样无法确定如何定义您的 ViewController 的不成熟 iOS 开发人员,请遵循以下代码

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

其中 Main 是情节提要文件名,iController 是 Main.Storyboard 文件中定义的 viewController 情节提要标识符

请为@jcesarmobile 给出的以上答案投票