我的想法是将Phonegap用于我的应用程序的业务逻辑,但使用原生过渡。所以我需要在每个UIViewController中使用CDVWebView。这适用于普通的UIWebviews,但如果我使用多个CDVViewControllers,例如在TabBar中,deviceReady事件仅为第一个CDVWebView触发。
以下是我在App Delegate中所做的事情:
- (BOOL) application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
{
NSURL* url = [launchOptions objectForKey:UIApplicationLaunchOptionsURLKey];
NSString* invokeString = nil;
if (url && [url isKindOfClass:[NSURL class]]) {
invokeString = [url absoluteString];
NSLog(@"NativeNavigationTest launchOptions = %@", url);
}
NSLog(@"invokeString = %@", invokeString);
CGRect screenBounds = [[UIScreen mainScreen] bounds];
self.window = [[[UIWindow alloc] initWithFrame:screenBounds] autorelease];
self.window.autoresizesSubviews = YES;
CGRect viewBounds = [[UIScreen mainScreen] applicationFrame];
//4 ViewController, each one inherits from CDVViewController
self.viewController = [[[MainViewController alloc] init] autorelease];
self.viewController.useSplashScreen = YES;
self.viewController.wwwFolderName = @"www";
self.viewController.startPage = @"index.html";
self.viewController.invokeString = invokeString;
self.viewController.view.frame = viewBounds;
self.secondController = [[[SecondController alloc] init] autorelease];
self.secondController.useSplashScreen = YES;
self.secondController.wwwFolderName = @"www";
self.secondController.startPage = @"second.html";
self.secondController.invokeString = invokeString;
self.secondController.view.frame = viewBounds;
self.thirdController = [[[ThirdController alloc] init] autorelease];
self.thirdController.useSplashScreen = YES;
self.thirdController.wwwFolderName = @"www";
self.thirdController.startPage = @"third.html";
self.thirdController.invokeString = invokeString;
self.thirdController.view.frame = viewBounds;
self.fourthController = [[[FourthController alloc] init] autorelease];
self.fourthController.useSplashScreen = YES;
self.fourthController.wwwFolderName = @"www";
self.fourthController.startPage = @"fourth.html";
self.fourthController.invokeString = invokeString;
self.fourthController.view.frame = viewBounds;
//add them in a native ViewController environment like a Tabbar
self.tabBarController = [[[UITabBarController alloc] init] autorelease];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:viewController, secondController, thirdController, fourthController, nil];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
return YES;
}
这是我为每个ViewController获得的错误,除了第一个。
Error: executing module function 'setInfo' in module 'cordova/plugin/ios/device'. Have you included the iOS version of the cordova-1.9.0.js
和
ERROR: Attempting to call cordova.exec() before 'deviceready'. Ignoring.
当然我在我的HTML文件中引用了cordova-1.9.0,我认为Cordova不是为了使用多个WebView而设计的,但有人知道如何更改它吗?
答案 0 :(得分:1)
答案是Cordova WebView。旨在嵌入本机应用程序。
修改强>
使用多个Cordova Webview,它具有相同的错误。当你仍然只能在你的项目中放置一个支持Phonegap的Webview时,我不知道它的重点。
答案 1 :(得分:1)
我确认这是一个race condition in Cordova - 问题从2.4.0开始修复。