objective-c - 具有多个 CDVViewController 的 Phonegap/Cordova

标签 objective-c ios cordova uiviewcontroller

我的想法是将 Phonegap 用于我的应用程序的业务逻辑,但使用 native 转换。所以我需要在每个 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 而设计的,但是有人知道如何更改它吗?

最佳答案

答案是Cordova WebView .旨在嵌入 native 应用程序。

编辑

使用 Multiple Cordova Webviews,它有相同的错误。当您仍然只能在您的项目中放置一个 Phonegap 支持的 Webview 时,我不知道这有什么意义。

关于objective-c - 具有多个 CDVViewController 的 Phonegap/Cordova,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13082330/

相关文章:

objective-c - 如何在 iOS 上使用 Facebook SDK 3.1 获取用户的电子邮件?

ios - Swift (iOS) - PickerView 未被 HTTP GET 请求填充

ios - 图表的动态 y 轴

ios - 如何在 iOS 中动态更改 UITabBar 图像

android - 基于 HTML 的手机应用程序在 Android 上比在 IOS 上更容易被接受?

iphone - 通用、可重复使用的 iPhone 应用程序配置屏幕

ios - 在 Objective C 项目中使用 Swift Pod

iphone - Web 服务或套接字级通信

android - PhoneGap 是我的正确选择吗?

cordova - 电话 : and mailto: links not working on iOS13 only