如何在Cordova中从CDVPlugin显示ViewController? [英] How To Show ViewController from CDVPlugin in Cordova?
问题描述
几天来我一直在为此苦苦挣扎,无法使它正常工作,也找不到其他人似乎已经解决了这个问题.希望有人能帮忙.
I have been struggling with this for a few days and cannot get it to work, nor find anyone else that seems to have figured this out. Hoping someone can help.
我在Swift的Storyboard中有一个带有2个视图的简单ViewController,我正尝试通过Cordova插件打开(Android版本有效).我已经知道它不会出错,并且我看到每行代码都被命中,但是我仍然没有看到ViewController的显示.该应用程序的独立版本可以正常工作.
I have a simple ViewController with 2 views in a Storyboard in Swift that I am trying to open through a Cordova plugin (Android version works). I have gotten it to the point where it does not error and I see every line of code being hit, but I am still not seeing the ViewController show. The standalone version of the application works fine.
这是插件调用的代码:
import Foundation
@objc(SomePlugin) class SomePlugin : CDVPlugin {
func show(command: CDVInvokedUrlCommand) {
// step 1. take a storyboard variable
var storyBoard:UIStoryboard? = nil
storyBoard = UIStoryboard(name: "Main", bundle: nil)
// step 2. un-box storyboard to sb variable
if let sb = storyBoard {
// step 3. create new window
var window = UIWindow(frame: UIScreen.mainScreen().bounds)
// step 4. start view controller
window.rootViewController = sb.instantiateInitialViewController() as ViewController
// step 5. make key window & visible
window.makeKeyAndVisible()
}
}
}
如果还有其他需要帮助的地方,请告诉我.预先感谢!
If anything else can be of help, please let me know. Thanks in advance!
推荐答案
第1步:需要将情节提要导入为
Step 1: Need to import your storyboard as
<resource-file src="src/ios/MyStoryboard.storyboard"/>
第2步:将您的框架导入为
Step 2: Import your framework as
<framework src="src/ios/helloSwiftFrame.framework" custom="true"/>
在plugin.xml中执行以上两个步骤
Do the above two steps in plugin.xml
第3步:现在进入插件中的.m文件
Step 3: Now to come to your .m file in your plugin
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MyStoryboard" bundle:nil];
UIViewController *yourViewController = [storyboard instantiateViewControllerWithIdentifier:@"MyStoryID"] ;
[self.viewController presentViewController: yourViewController animated:YES completion:nil];
也不要忘记将框架导入.m文件.
also don't forget to import your framework in .m file.
就这样了.. !!快乐编码
That's it done..!! Happy Coding
这篇关于如何在Cordova中从CDVPlugin显示ViewController?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!