参考:
开发环境:
XCode 4.6
Cordova 2.3.0
准备工作
<1 新建config.xml文件
新建config.xml文件,添加到项目中。
<2 创建www目录
在项目根目录下,创建文件夹www
在www文件夹下,新建文件index.html文件
范例:
Hello World!
“Create folder references for any added folder”,添加到项目中
1、添加CordovaLib子项目
cordova-2.3.0/cordova-ios/CordovaLib下,将CordovaLib.xcodeproj拖拽到项目中
TARGET-> Build Settings -> Other Linker Flags,添加 -all_load
和 -Obj-C
TARGET -> Build Phases -> Link Binaries with Libraries,添加一下frameworks:
AddressBook.framework
AddressBookUI.framework
AudioToolbox.framework
AVFoundation.framework
CoreLocation.framework
MediaPlayer.framework
QuartzCore.framework
SystemConfiguration.framework
MobileCoreServices.framework
CoreMedia.framework
TARGET -> Build Phases -> Target Dependencies,添加CordovaLib
TARGET -> Build Phases -> Link Binaries with Libraries,添加CordovaLia.a
TARGET-> Build Settings -> Header Search Path,添加一下项:(注意:带引号)
"$(TARGET_BUILD_DIR)/usr/local/lib/include"
"$(OBJROOT)/UninstalledProducts/include"
"$(BUILT_PRODUCTS_DIR)"
2、使用
新建CDVViewController子类
示例:
#import#import @interface ViewController : CDVViewController@end
设置该对象的wwwFolderName属性,
startPage属性
示例:
#import "AppDelegate.h"#import "ViewController.h"@implementation AppDelegate- (void)dealloc{ [_window release]; [_viewController release]; [super dealloc];}- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{ self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; self.viewController = [[ViewController new] autorelease]; self.viewController.wwwFolderName = @"www"; self.viewController.startPage = @"index.html"; self.viewController.useSplashScreen = YES; self.window.rootViewController = self.viewController; [self.window makeKeyAndVisible]; return YES;}@end
运行结果: