1:如何在Cordoval加載遠(yuǎn)程的URL網(wǎng)址
在Config.xml配置文件時(shí)增加下面兩個(gè),便可以打開URL的HTML頁(yè)面
2:在Cordoval中加載同一個(gè)域的URL是在APP打開,跳轉(zhuǎn)到其它卻是用safari瀏覽器打開
同樣是在Config.xml配置中把下面兩個(gè)刪除,這樣它便會(huì)一直在APP里面進(jìn)行跳轉(zhuǎn)
3:如何加載不同的啟動(dòng)頁(yè)URL地址
在配置Config.xml文件中有個(gè)content的節(jié)點(diǎn),里面默認(rèn)是有一個(gè)打開本地的地址index.html(比如:);這個(gè)就是跳轉(zhuǎn)到本地包里面的html頁(yè)面,也可以修改成(比如:);
上面這種只是修改默認(rèn)的地址,可能不符合對(duì)于項(xiàng)目實(shí)際用法,項(xiàng)目中要加載Cordova都會(huì)有一個(gè)viewController的控制器繼承于CDVViewController,它時(shí)就有一個(gè)屬性startPage用于設(shè)置跳到webView加載的html頁(yè)面;其中使用CDVViewController通常需要設(shè)置wwwFolderName的目錄名稱,和startPage首頁(yè)的名稱即可。默認(rèn)wwwFolderName為www,startPage默認(rèn)為index.html;這個(gè)也是模板直接生成時(shí)文件的名稱;
self.viewController.startPage=@"http://www.cnblogs.com";
4:如何加載HTML頁(yè)面存放在盒沙中

self.viewController =[[MainViewController alloc] init];
NSString*curFilePath=[NSString stringWithFormat:@"file://%@/www",[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]];
NSLog(@"路徑為:%@",curFilePath);if([[NSFileManager defaultManager] fileExistsAtPath:curFilePath]) {
self.viewController.wwwFolderName=curFilePath;
}
self.viewController.startPage=@"index.html";

同樣是在wwwFolderName上做文章,因?yàn)樗乔熬Y文件夾的路徑,這邊要注意是關(guān)于路徑要運(yùn)用file://方式進(jìn)行讀?。?/p>

因?yàn)榭梢宰x取沙盒里面的HTML頁(yè)面,這樣我們就可以更加靈活運(yùn)用,比如HTML通過(guò)服務(wù)端去下載到沙盒解壓,這樣就可以做到動(dòng)態(tài)修改;
5:加載頁(yè)面跟結(jié)束加載頁(yè)面的監(jiān)聽,有兩個(gè)通知可以監(jiān)聽,用來(lái)處理等待效果展現(xiàn)

- (void)viewDidLoad
{
[super viewDidLoad];//Do any additional setup after loading the view from its nib.NSNotificationCenter*center =[NSNotificationCenter defaultCenter];
[center addObserver:self
selector:@selector(onNotification:)
name:CDVPluginResetNotification//開始加載object:nil];
[center addObserver:self
selector:@selector(onNotificationed:)
name:CDVPageDidLoadNotification//加載完成object:nil];
}- (void)onNotification:(NSNotification *)text{
NSLog(@"-----開始等待------");
}- (void)onNotificationed:(NSNotification *)text{
NSLog(@"-----結(jié)束等待------");
}

6:刷新UIWebView,UIWebView直接更改url并reload是沒有用的。必須聲明一個(gè)NSURLRequest,并重新loadRequest。刷新時(shí)的url必須是符合Cordova規(guī)則的url。在Cordova源碼中有一個(gè)appUrl的方法,通過(guò)這個(gè)方法轉(zhuǎn)出的url才能被CDVViewController正常加載;

localWebVC.wwwFolderName =@"www";
localWebVC.startPage=@"local.html";
NSURL*url =[self.localWebVC performSelector:@selector(appUrl)];if(url)
{
NSURLRequest*request =[[NSURLRequest alloc] initWithURL:url];
[self.localWebVC.webView loadRequest:request];
}

7:使用pod管理Cordoval及其插件
pod'Cordova'
如果需要引入一些相關(guān)的插件,可以加入如下配置,下面的這些插件可以通過(guò)pod搜索到:

pod'CordovaPlugin-console'pod'cordova-plugin-camera'pod'cordova-plugin-contacts'pod'cordova-plugin-device'pod'cordova-plugin-device-orientation'pod'cordova-plugin-device-motion'pod'cordova-plugin-globalization'pod'cordova-plugin-geolocation'pod'cordova-plugin-file'pod'cordova-plugin-media-capture'pod'cordova-plugin-network-information'pod'cordova-plugin-splashscreen'pod'cordova-plugin-inappbrowser'pod'cordova-plugin-file-transfer'pod'cordova-plugin-statusbar'pod'cordova-plugin-vibration'

注意:如果沒有用pod來(lái)管理Cordova,默認(rèn)工程都會(huì)有一個(gè)CordovaLib.xcodeproj來(lái)把Cordova的類引入,所以建議Cordova用pod引入,就可以調(diào)用,而關(guān)于html、JS等靜態(tài)模板還是在工程中;可以查看下面兩個(gè)網(wǎng)址
iOS中Cordova開發(fā)初探 地址:http://blog.devzeng.com/blog/hello-cordova-ios.html
Cordova使用Pod實(shí)例 地址:https://github.com/phonegap/phonegap-webview-ios
三:插件內(nèi)容
對(duì)于Cordova在插件上面還是比較多,也可以自定義插件的開發(fā),對(duì)于插件下面已經(jīng)有列出一些,其它插件可以上Cordova或者gitHub進(jìn)行查找;

支付寶支付插件:
iOS/Android 地址:https://github.com/fami2u/cordova-plugin-alipay.git微信支付插件:
iOS/Android 地址:https://github.com/fami2u/cordova-plugin-weipay.gitping++支付插件:
iOS 地址:https://github.com/fami2u/cordova-ping-fami.git掃描二維碼和條形碼插件:
iOS/Android 地址:https://github.com/fami2u/cordova-barcodescanner-fami.git拍照插件:
iOS/Android 地址:https://github.com/fami2u/cordova-plugin-camera.git極光推送插件:
iOS/Android 地址:https://github.com/fami2u/jpush-phonegap-plugin.gitiOS 地址:https://github.com/fami2u/cordova-Jpush-fami.git第三方登錄插件:
iOS 地址:https://github.com/fami2u/cordova-UMLogin-fami.gitJS 地址:https://github.com/fami2u/cordova-plugin-wechat.git第三方分享插件:
iOS 地址:https://github.com/fami2u/cordova-UMShare-fami.git跳轉(zhuǎn)地圖插件:
iOS 地址:https://github.com/fami2u/cordova-plugin-map.git視頻播放插件:
iOS 地址:https://github.com/fami2u/cordova-player-fami.git

四:有可能出現(xiàn)的問(wèn)題
1:在使用cordova6.0的過(guò)程中,編譯好的APP運(yùn)行在IOS7+系統(tǒng)上默認(rèn)是與狀態(tài)欄重疊的,而運(yùn)行在IOS6及老版本中時(shí)是于狀態(tài)欄分離的。
解決辦法:把文件MainViewController.m中的方法viewWillAppear進(jìn)行相關(guān)修改如下。作用是更改view的邊界,使其下移20px,剛好是狀態(tài)欄的高度。

- (void)viewWillAppear:(BOOL)animated
{if([[[UIDevice currentDevice]systemVersion ] floatValue]>=7)
{
CGRect viewBounds=[self.webView? bounds];
viewBounds.origin.y=20;
viewBounds.size.height=viewBounds.size.height-20;
self.webView.frame=viewBounds;
}
[super viewWillAppear:animated];
}

2:在html頁(yè)面內(nèi)調(diào)用系統(tǒng)相機(jī)以后再返回,整個(gè)頁(yè)面底部會(huì)有白色的空白控件,用調(diào)試工具查看后空白區(qū)域的高度是20px.該如何解決?
解決辦法:由于整個(gè)cordova項(xiàng)目相當(dāng)于一個(gè)頁(yè)面的應(yīng)用,不同的模塊聚集在一起,所以當(dāng)當(dāng)前屏幕消失后(比如進(jìn)入系統(tǒng)相機(jī)拍照頁(yè)面)再出現(xiàn)的時(shí)候,還是會(huì)執(zhí)行上面的代碼,所以界面高度再次減少20px.

-(void)viewWillDisappear:(BOOL)animated
{if([[[UIDevice currentDevice]systemVersion ] floatValue]>=7)
{
CGRect viewBounds=[self.webView? bounds];
viewBounds.origin.y=20;
viewBounds.size.height=viewBounds.size.height+20;
self.webView.frame=viewBounds;
}
[super viewWillDisappear:animated];
}

六:JS跟OC交互實(shí)例
? ? ? ? ? ? Capture Photo? ? ? ? ? ? ? ? //簡(jiǎn)單跟OC交互,沒有回調(diào)//function test()//{//options={quality:"200"};//cordova.exec(null,null,'HelloWorld','sayHello',[options]);//}function test()
{
options={quality:"200"};
cordova.exec(
function(result){vars=result;
alert(s);
},
function(error)
{
alert("error",error);
}
,'HelloWorld','sayHello',[options]);
}? ? ? ? ? ? ? ? 交互OC
? ?

可以查看文章對(duì)于插件的編寫有進(jìn)一步的說(shuō)明,http://www.itdecent.cn/p/e982b9a85ae8
七:分享Cordova不錯(cuò)的文章:
使用Cordova進(jìn)行iOS開發(fā) (環(huán)境配置及基本用法) :http://www.itdecent.cn/p/d24219c008b6
使用Cordova進(jìn)行iOS開發(fā) (第三方插件的使用:Camera插件):http://www.itdecent.cn/p/1e3d0c915dbc
使用Cordova進(jìn)行iOS開發(fā) (已存的項(xiàng)目中添加Cordova及自定義插件):http://www.itdecent.cn/p/e982b9a85ae8
Cordova插件開發(fā)入門(IOS版OC跟JS交互):http://my.oschina.net/crazymus/blog/516388
淺析 Cordova for iOS(OC跟JS交互的說(shuō)明):http://www.cocoachina.com/industry/20130520/6238.html
cordova CDVViewController解析:http://blog.csdn.net/u011417590/article/details/50895734
附整理的Cordova小實(shí)例:https://github.com/wujunyang/jiaCordovaDemo