1.可以使用webGl做离线存储
2.随机数方法
//随机数
function uuid() {
var s = [];
var hexDigits = "0123456789abcdef";
for (var i = 0; i < 36; i++) {
s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
}
s[14] = "4"; // bits 12-15 of the time_hi_and_version field to 0010
s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1); // bits 6-7 of the clock_seq_hi_and_reserved to 01
s[8] = s[13] = s[18] = s[23] = "-";
var uuid = s.join("");
return uuid;
}
3.图片上传base64要比二进制流上传要快
4.h5中如果用到
var main = plus.android.runtimeMainActivity();
main.onActivityResult=null;
最后要清空,否则在app中会一直有缓存。
5.上传前图片压缩可以结合如下两个方法
plus.io.resolveLocalFileSystemURL(_filePath[0], function (entry) {
//var a = entry.toLocalURL();//本地流文件
plus.zip.compressImage({
src: entry.toLocalURL(),
dst: "_doc/a.jpg",
overwrite: true,
width: '500px',
height: 'auto',
format: 'jpg',
quality: 100
},
function (e) {
var reader = new plus.io.FileReader();
reader.onloadend = function (e) {
var speech = e.target.result; //base64图片
};
eader.readAsDataURL(e.target);
},
function (err) {
plus.nativeUI.alert('未知错误!', function () {});
});
}, function (e) {
mui.toast('读取拍照文件错误:' + e.message);
});
用FileReader去转base64;
6.代码异步问题,可以在for循环遍历到最后时立flag处理(多个图片转base64遇到的问题,或许有更好的处理方式,正在探索)。
7.前端遍历1万条数据大约1秒钟的时间。
8.app中打开另一个app的方法
plus.runtime.launchApplication({
pname:"cn.sunshine.abkc"}, function ( e ) {
plus.nativeUI.confirm("检查到您未安装\"安标快查\",是否到商城搜索下载?", function(i){
if(i.index == 0 ){
androidMarket("cn.sunshine.abkc" );
}
});
});
9. 项目做自动升级的时候manifest.json中的
"version" : {
"name" : "1.0.9", /*应用版本名称*/
"code" : 1107
}可以做标识判断
10.app自动升级下载包 可以有两种方式 一种是wgtu文件 一种是apk看业务要求。如下代码是更新下载的apk,wgtu文件时把注释的放开,plus.runtime.openFile(d.filename)注释即可。
var dtask = plus.downloader.createDownload(result.installUrl,
{method:"GET", filename: "_doc/download/" + 'jlApk.apk'}, function(d,status){
if ( status == 200 ) {
//alert(JSON.stringify(d))
//alert( "Download wgtu success: " + d.filename );
plus.runtime.openFile(d.filename);
//plus.runtime.install(d.filename,{},function(){
/plus.nativeUI.closeWaiting();
//plus.nativeUI.alert("Update wgtu success, restart now!",function(){
// plus.runtime.restart();
// });
//},function(e){
// plus.nativeUI.closeWaiting();
// mui.toast("Update wgtu failed: "+e.message);
// });
} else {
plus.nativeUI.closeWaiting();
mui.toast( "Download wgtu failed: " + status );
}
});
dtask.addEventListener('statechanged',function(d,status){
console.log("statechanged: "+d.state);
});
dtask.start();
10. 5+sdk api https://www.html5plus.org/doc/zh_cn/io.html
11.app退出应用 plus.runtime.quit();
12.for in遍历未知键值对
var jsonObj = {"55":"1","70":"0","80":"2","60":"2"};
for (var prop in jsonObj)
{
alert("jsonObj[" + prop + "]=" + jsonObj[prop]);
}
14.数组扁平化 [1, [2, [3, [4, 5]]], 6].flat(Infinity)