Skip to content

Commit

Permalink
积累更新
Browse files Browse the repository at this point in the history
  • Loading branch information
tower1229 committed Aug 31, 2017
1 parent 970b809 commit 9754104
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 23 deletions.
2 changes: 2 additions & 0 deletions config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
<permission name="internet"/>
<permission name="bootCompleted"/>
<permission name="hardware"/>
<preference name="urlScheme" value="hybridstart" />
<preference name="querySchemes" value="hybridstart" />
<preference name="customRefreshHeader" value="UIPullRefreshFlash"/>
<preference name="backgroundMode" value="location"/>
<access origin="*"/>
Expand Down
19 changes: 19 additions & 0 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,14 @@ <h3 id="getStart">快速开始</h3>
</ol>

<h4>配置</h4>

<p>config.xml包含原生层面的所有配置,详情参考<a href="http://docs.apicloud.com/Dev-Guide/app-config-manual" target="_blank">config.xml应用配置说明</a>,另外如果需要应用内升级,请一定记得修改config.xml里的scheme值,否则IOS9以上系统无法升级</p>
<pre>
<code>
&lt;preference name=&quot;urlScheme&quot; value=&quot;hybridstart&quot; /&gt;
&lt;preference name=&quot;querySchemes&quot; value=&quot;hybridstart&quot; /&gt;
</code>
</pre>
<p><code>config.js</code>文件是HybridStart的全局配置,所有配置信息挂载在<code>appcfg</code>对象上,包含APP开发的全部配置,也可以自行扩展其他配置。</p>
<p>默认如下:</p>
<table class="table table-bordered">
Expand Down Expand Up @@ -2551,6 +2559,17 @@ <h3 id="solution-preget">数据预取</h3>
});
</code>
</pre>
<h3 id="solution-update">自动更新</h3>
<p>借助平台的版本管理机制实现APP自动更新,config.xml默认已配置autoUpdate,APP启动时将自动检测新版本并提示,另外server.js中封装了一个checkUpdate()方法,用于应用内手动检测更新。</p>
<pre>
<code>
var comm = require('sdk/server');
comm.checkUpdate();
</code>
</pre>
<h3 id="solution-push">消息推送</h3>
<p>框架内置基于极光推送实现的推送机制,root页面默认包含推送初始化代码,config.xml中的极光app_key需要自己申请并替换,server.js中封装了push对象,包含open()和close()两个方法,用于实现推送开关,具体实现参见<code>view/member/set/script.js</code></p>

</section>
<footer class="wrap oh tc">
<div class="row ">
Expand Down
2 changes: 1 addition & 1 deletion docs/seajs.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
seajs.root = '/HybridStart/docs';
seajs.root = '/docs';//'/HybridStart/docs';
seajs.config({
base: "http://static-zt.oss-cn-qingdao.aliyuncs.com/modules",
paths: {
Expand Down
10 changes: 6 additions & 4 deletions sdk/core.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/*
app JS SDK
Version:2.3.1
update: _openToast支持(msg, delay)语法
date:2017-08-14
Version:2.2.4
update: slidBackEnabled默认false
date:2017-08-30
*
/*! Sea.js 2.2.1 | seajs.org/LICENSE.md */
!function(a,b){function c(a){return function(b){return{}.toString.call(b)=="[object "+a+"]"}}function d(){return A++}function e(a){return a.match(D)[0]}function f(a){for(a=a.replace(E,"/");a.match(F);)a=a.replace(F,"/");return a=a.replace(G,"$1/")}function g(a){var b=a.length-1,c=a.charAt(b);return"#"===c?a.substring(0,b):".js"===a.substring(b-2)||a.indexOf("?")>0||".css"===a.substring(b-3)||"/"===c?a:a+".js"}function h(a){var b=v.alias;return b&&x(b[a])?b[a]:a}function i(a){var b=v.paths,c;return b&&(c=a.match(H))&&x(b[c[1]])&&(a=b[c[1]]+c[2]),a}function j(a){var b=v.vars;return b&&a.indexOf("{")>-1&&(a=a.replace(I,function(a,c){return x(b[c])?b[c]:a})),a}function k(a){var b=v.map,c=a;if(b)for(var d=0,e=b.length;e>d;d++){var f=b[d];if(c=z(f)?f(a)||a:a.replace(f[0],f[1]),c!==a)break}return c}function l(a,b){var c,d=a.charAt(0);if(J.test(a))c=a;else if("."===d)c=f((b?e(b):v.cwd)+a);else if("/"===d){var g=v.cwd.match(K);c=g?g[0]+a.substring(1):a}else c=v.base+a;return 0===c.indexOf("//")&&(c=location.protocol+c),c}function m(a,b){if(!a)return"";a=h(a),a=i(a),a=j(a),a=g(a);var c=l(a,b);return c=k(c)}function n(a){return a.hasAttribute?a.src:a.getAttribute("src",4)}function o(a,b,c){var d=S.test(a),e=L.createElement(d?"link":"script");if(c){var f=z(c)?c(a):c;f&&(e.charset=f)}p(e,b,d,a),d?(e.rel="stylesheet",e.href=a):(e.async=!0,e.src=a),T=e,R?Q.insertBefore(e,R):Q.appendChild(e),T=null}function p(a,c,d,e){function f(){a.onload=a.onerror=a.onreadystatechange=null,d||v.debug||Q.removeChild(a),a=null,c()}var g="onload"in a;return!d||!V&&g?(g?(a.onload=f,a.onerror=function(){C("error",{uri:e,node:a}),f()}):a.onreadystatechange=function(){/loaded|complete/.test(a.readyState)&&f()},b):(setTimeout(function(){q(a,c)},1),b)}function q(a,b){var c=a.sheet,d;if(V)c&&(d=!0);else if(c)try{c.cssRules&&(d=!0)}catch(e){"NS_ERROR_DOM_SECURITY_ERR"===e.name&&(d=!0)}setTimeout(function(){d?b():q(a,b)},20)}function r(){if(T)return T;if(U&&"interactive"===U.readyState)return U;for(var a=Q.getElementsByTagName("script"),b=a.length-1;b>=0;b--){var c=a[b];if("interactive"===c.readyState)return U=c}}function s(a){var b=[];return a.replace(X,"").replace(W,function(a,c,d){d&&b.push(d)}),b}function t(a,b){this.uri=a,this.dependencies=b||[],this.exports=null,this.status=0,this._waitings={},this._remain=0}if(!a.seajs){var u=a.seajs={version:"2.2.1"},v=u.data={},w=c("Object"),x=c("String"),y=Array.isArray||c("Array"),z=c("Function"),A=0,B=v.events={};u.on=function(a,b){var c=B[a]||(B[a]=[]);return c.push(b),u},u.off=function(a,b){if(!a&&!b)return B=v.events={},u;var c=B[a];if(c)if(b)for(var d=c.length-1;d>=0;d--)c[d]===b&&c.splice(d,1);else delete B[a];return u};var C=u.emit=function(a,b){var c=B[a],d;if(c)for(c=c.slice();d=c.shift();)d(b);return u},D=/[^?#]*\//,E=/\/\.\//g,F=/\/[^/]+\/\.\.\//,G=/([^:/])\/\//g,H=/^([^/:]+)(\/.+)$/,I=/{([^{]+)}/g,J=/^\/\/.|:\//,K=/^.*?\/\/.*?\//,L=document,M=e(L.URL),N=L.scripts,O=L.getElementById("seajsnode")||N[N.length-1],P=e(n(O)||M);u.resolve=m;var Q=L.head||L.getElementsByTagName("head")[0]||L.documentElement,R=Q.getElementsByTagName("base")[0],S=/\.css(?:\?|$)/i,T,U,V=+navigator.userAgent.replace(/.*(?:AppleWebKit|AndroidWebKit)\/(\d+).*/,"$1")<536;u.request=o;var W=/"(?:\\"|[^"])*"|'(?:\\'|[^'])*'|\/\*[\S\s]*?\*\/|\/(?:\\\/|[^\/\r\n])+\/(?=[^\/])|\/\/.*|\.\s*require|(?:^|[^$])\brequire\s*\(\s*(["'])(.+?)\1\s*\)/g,X=/\\\\/g,Y=u.cache={},Z,$={},_={},ab={},bb=t.STATUS={FETCHING:1,SAVED:2,LOADING:3,LOADED:4,EXECUTING:5,EXECUTED:6};t.prototype.resolve=function(){for(var a=this,b=a.dependencies,c=[],d=0,e=b.length;e>d;d++)c[d]=t.resolve(b[d],a.uri);return c},t.prototype.load=function(){var a=this;if(!(a.status>=bb.LOADING)){a.status=bb.LOADING;var c=a.resolve();C("load",c);for(var d=a._remain=c.length,e,f=0;d>f;f++)e=t.get(c[f]),e.status<bb.LOADED?e._waitings[a.uri]=(e._waitings[a.uri]||0)+1:a._remain--;if(0===a._remain)return a.onload(),b;var g={};for(f=0;d>f;f++)e=Y[c[f]],e.status<bb.FETCHING?e.fetch(g):e.status===bb.SAVED&&e.load();for(var h in g)g.hasOwnProperty(h)&&g[h]()}},t.prototype.onload=function(){var a=this;a.status=bb.LOADED,a.callback&&a.callback();var b=a._waitings,c,d;for(c in b)b.hasOwnProperty(c)&&(d=Y[c],d._remain-=b[c],0===d._remain&&d.onload());delete a._waitings,delete a._remain},t.prototype.fetch=function(a){function c(){u.request(g.requestUri,g.onRequest,g.charset)}function d(){delete $[h],_[h]=!0,Z&&(t.save(f,Z),Z=null);var a,b=ab[h];for(delete ab[h];a=b.shift();)a.load()}var e=this,f=e.uri;e.status=bb.FETCHING;var g={uri:f};C("fetch",g);var h=g.requestUri||f;return!h||_[h]?(e.load(),b):$[h]?(ab[h].push(e),b):($[h]=!0,ab[h]=[e],C("request",g={uri:f,requestUri:h,onRequest:d,charset:v.charset}),g.requested||(a?a[g.requestUri]=c:c()),b)},t.prototype.exec=function(){function a(b){return t.get(a.resolve(b)).exec()}var c=this;if(c.status>=bb.EXECUTING)return c.exports;c.status=bb.EXECUTING;var e=c.uri;a.resolve=function(a){return t.resolve(a,e)},a.async=function(b,c){return t.use(b,c,e+"_async_"+d()),a};var f=c.factory,g=z(f)?f(a,c.exports={},c):f;return g===b&&(g=c.exports),delete c.factory,c.exports=g,c.status=bb.EXECUTED,C("exec",c),g},t.resolve=function(a,b){var c={id:a,refUri:b};return C("resolve",c),c.uri||u.resolve(c.id,b)},t.define=function(a,c,d){var e=arguments.length;1===e?(d=a,a=b):2===e&&(d=c,y(a)?(c=a,a=b):c=b),!y(c)&&z(d)&&(c=s(""+d));var f={id:a,uri:t.resolve(a),deps:c,factory:d};if(!f.uri&&L.attachEvent){var g=r();g&&(f.uri=g.src)}C("define",f),f.uri?t.save(f.uri,f):Z=f},t.save=function(a,b){var c=t.get(a);c.status<bb.SAVED&&(c.id=b.id||a,c.dependencies=b.deps||[],c.factory=b.factory,c.status=bb.SAVED)},t.get=function(a,b){return Y[a]||(Y[a]=new t(a,b))},t.use=function(b,c,d){var e=t.get(d,y(b)?b:[b]);e.callback=function(){for(var b=[],d=e.resolve(),f=0,g=d.length;g>f;f++)b[f]=Y[d[f]].exec();c&&c.apply(a,b),delete e.callback},e.load()},t.preload=function(a){var b=v.preload,c=b.length;c?t.use(b,function(){b.splice(0,c),t.preload(a)},v.cwd+"_preload_"+d()):a()},u.use=function(a,b){return t.preload(function(){t.use(a,b,v.cwd+"_use_"+d())}),u},t.define.cmd={},a.define=t.define,u.Module=t,v.fetchedList=_,v.cid=d,u.require=function(a){var b=t.get(t.resolve(a));return b.status<bb.EXECUTING&&(b.onload(),b.exec()),b.exports};var cb=/^(.+?\/)(\?\?)?(seajs\/)+/;v.base=(P.match(cb)||["",P])[1],v.dir=P,v.cwd=M,v.charset="utf-8",v.preload=function(){var a=[],b=location.search.replace(/(seajs-\w+)(&|$)/g,"$1=1$2");return b+=" "+L.cookie,b.replace(/(seajs-\w+)=1/g,function(b,c){a.push(c)}),a}(),u.config=function(a){for(var b in a){var c=a[b],d=v[b];if(d&&w(d))for(var e in c)d[e]=c[e];else y(d)?c=d.concat(c):"base"===b&&("/"!==c.slice(-1)&&(c+="/"),c=l(c)),v[b]=c}return C("config",a),u}}}(this);
Expand Down Expand Up @@ -828,7 +829,8 @@ var apputil = (function(document, undefined) {
},
progress: {
type: 'page'
}
},
slidBackEnabled:false
}));
return config.name;
} else {
Expand Down
25 changes: 12 additions & 13 deletions sdk/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,9 @@ define(function(require, exports, module) {
};

//数据预取
var preGet = function(cb) {
var _preGet = function(cb) {
var got = 0,
preGetList = preGet.prototype.preGetList,
preGetList = _preGet.prototype.preGetList,
getOne = function() {
got++;
if (got >= preGetList.length && typeof(cb) === 'function') {
Expand Down Expand Up @@ -220,29 +220,29 @@ define(function(require, exports, module) {
});
};
//预取配置信息
preGet.prototype.preGetList = [{
_preGet.prototype.preGetList = [{
key: 'websiteConfig',
url: appcfg.host.control + '/websiteConfig',
data: {}
}];

//预取数据
var checkPreget = function() {
var preGetList = preGet.prototype.preGetList,
var _checkPreget = function() {
var preGetList = _preGet.prototype.preGetList,
isDone = true;
$.each(preGetList, function(i, e) {
if (!app.storage.val(e.key)) {
preGet();
_preGet();
isDone = false;
return false;
}
});
return isDone;
};
//检查升级
var _checkUpdate = function(platform, silence) {
var _checkUpdate = function(silence) {
var mam = api.require('mam');

var platform = api.systemType;
mam.checkUpdate(function(ret, err) {
if (ret) {
var result = ret.result;
Expand All @@ -253,14 +253,13 @@ define(function(require, exports, module) {
appUri: result.source
});
} else if (platform == 'android') {
app.loading.show('正在下载');
api.download({
url: result.source,
report: true
}, function(ret, err) {
if (ret && 0 === ret.state) { /* 下载进度 */
app.toast("正在下载:" + ret.percent + "%", 1000);
}
if (ret && 1 === ret.state) { /* 下载完成 */
app.loading.hide();
var savePath = ret.savePath;
api.installApp({
appUri: savePath
Expand Down Expand Up @@ -418,8 +417,8 @@ define(function(require, exports, module) {
initUser: _initUser,
getUser: _getUser,
push: _push,
preGet: preGet,
checkPreget: checkPreget,
preGet: _preGet,
checkPreget: _checkPreget,
source: _source,
getDate: _getDate,
checkUpdate: _checkUpdate,
Expand Down
5 changes: 4 additions & 1 deletion view/member/set/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ define(function(require) {
var $ = app.util;
var globalTimeout;

$("#ver")[0].innerText = (appcfg.set.version || '0.0.1');
$("#ver")[0].innerText = (appcfg.set.version || api.appVersion);

//接收推送
var pushable = app.storage.val('pushable');
Expand Down Expand Up @@ -57,6 +57,9 @@ define(function(require) {
lst = null;
}, appcfg.set.outime);
break;
case "upload":
comm.checkUpdate();
break;
case "exit":
comm.logout();
break;
Expand Down
2 changes: 1 addition & 1 deletion view/member/set/temp.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
</div>
</div>
<div class="list ">
<div class="item" data-action="upload" id="checkUpload">
<div class="item" data-action="upload">
<div class="item-note">版本号 V<span id="ver"></span></div>
检查更新
</div>
Expand Down
3 changes: 0 additions & 3 deletions view/root/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,6 @@ define(function(require) {
//预取数据
comm.checkPreget();

//检查更新
comm.checkUpdate(api.systemType, true);

//app启动&恢复事件
app.on('resume', function() {
ajpush.onResume();
Expand Down

0 comments on commit 9754104

Please sign in to comment.