6:改写uiwebview,uiwebview直接更改url并reload是没有用的。有必要声明一个nsurlrequest,并从头loadrequest。改写时的url有必要是契合cordova规矩的url。在cordova中有一个appurl的办法,经过这个办法转出的url才干被cdvviewcontroller正常加载;
localwebvc.wwwfoldername = @ www
localwebvc.startpage = @ local.html
nsurl *url = [self.localwebvc performselector:@selector];
if
nsurlrequest *request = [[nsurlrequest alloc] initwithurl:url];
[self.localwebvc.webview loadrequest:request];
}
7:运用pod办理cordoval及其插件
pod cordova
假如需求引进一些相关的插件,能够参加如下装备,下面的这些插件能够经过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来办理cordova,默许工程都会有一个cordovalib.xcodeproj来把cordova的类引进,所以主张cordova用pod引进,就能够调用,而关于html、js等静态模板仍是在工程中;能够检查下面两个网址
ios中cordova开发初探 地址:
cordova运用pod实例 地址:
三:插件内容
关于cordova在插件上面仍是比较多,也能够自定义插件的开发,关于插件下面已经有列出一些,其它插件能够上cordova或许github进行查找;
付出宝付出插件:
ios/android 地址:https://github.com/fami2u/cordova-plugin-alipay.git
微信付出插件:
ios/android 地址:https://github.com/fami2u/cordova-plugin-weipay.git
ping++付出插件:
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.git
ios 地址:https://github.com/fami2u/cordova-jpush-fami.git
第三方登录插件:
ios 地址:https://github.com/fami2u/cordova-umlogin-fami.git
js 地址:https://github.com/fami2u/cordova-plugin-wechat.git
第三方共享插件:
ios 地址:https://github.com/fami2u/cordova-umshare-fami.git
跳转地图插件:
ios 地址:https://github.com/fami2u/cordova-plugin-map.git
视频播映插件:
ios 地址:https://github.com/fami2u/cordova-player-fami.git
四:有或许呈现的问题
1:在运用cordova6.0的过程中,编译好的app运行在ios7+体系上默许是与状态栏堆叠的,而运行在ios6及老版别中时是于状态栏别离的。
处理办法:把文件mainviewcontroller.m中的办法viewwillappear进行相关修正如下。作用是更改view的鸿沟,使其下移20px,刚好是状态栏的高度。
- viewwillappear:animated
if
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页面内调用体系相机今后再回来,整个页面底部会有白色的空白控件,用调试东西检查后空白区域的高度是20px.该怎么处理?
处理办法:由于整个cordova项目相当于一个页面的运用,不同的模块集合在一起,所以当当时屏幕消失后再呈现的时分,仍是会履行上面的代码,所以界面高度再次削减20px.
-viewwilldisappear:animated
if
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交互实例
1:由于cordoval要跟js交互都是要使用cdvplugin进行
#import
#import
@interface cdvhelloworld : cdvplugin
-sayhello:command;
@end
所以咱们创立一个插件类,承继于cdvplugin类,其间cdvinvokedurlcommand便是用于交互的类;
#import cdvhelloworld.h
@implementation cdvhelloworld
-sayhello:command
//接纳js传过来的值
nsdictionary *options=[command argumentatindex:0 withdefault:nil];
//对应键名
nsstring *curvalue=options[@ quality
uialertview *myalertview=[[uialertview alloc]initwithtitle:@ 我是小实例 message:[nsstring stringwithformat:@ 当时的内容从js传过来的值为:%@ ,curvalue] delegate:self cancelbuttontitle:@ 撤销 otherbuttontitles:@ 确认 , nil];
[myalertview show];