{"id":32525,"date":"2024-03-06T15:40:29","date_gmt":"2024-03-06T07:40:29","guid":{"rendered":"https:\/\/app.applebyme.cn\/cloud\/?p=32525"},"modified":"2024-03-06T15:40:29","modified_gmt":"2024-03-06T07:40:29","slug":"%e7%bd%91%e9%a1%b5%e5%ae%89%e8%a3%85app%e6%b3%a8%e6%84%8f%e4%ba%8b%e9%a1%b9%e4%bb%8b%e7%bb%8d","status":"publish","type":"post","link":"https:\/\/app.applebyme.cn\/cloud\/appkaifa\/32525.html","title":{"rendered":"\u7f51\u9875\u5b89\u88c5app\u6ce8\u610f\u4e8b\u9879\u4ecb\u7ecd"},"content":{"rendered":"<p>\u7f51\u9875\u5b89\u88c5App\u662f\u4e00\u79cd\u63d0\u4f9b\u7ed9\u7528\u6237\u76f4\u63a5\u5728\u7f51\u9875\u4e0a\u4e0b\u8f7d\u548c\u5b89\u88c5\u79fb\u52a8\u5e94\u7528\u7a0b\u5e8f\u7684\u65b9\u5f0f\u3002\u8fd9\u79cd\u65b9\u5f0f\u8d8a\u6765\u8d8a\u53d7\u5230\u5f00\u53d1\u8005\u548c\u7528\u6237\u7684\u6b22\u8fce\uff0c\u56e0\u4e3a\u5b83\u7b80\u5316\u4e86\u7a0b\u5e8f\u7684\u5206\u53d1\u8fc7\u7a0b\uff0c\u7528\u6237\u65e0\u9700\u8bbf\u95ee\u5e94\u7528\u5546\u5e97\u5373\u53ef\u83b7\u5f97\u6240\u9700\u7684\u5e94\u7528\u7a0b\u5e8f\u3002\u672c\u6587\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u7f51\u9875\u5b89\u88c5App\u7684\u539f\u7406\u53ca\u76f8\u5173\u6280\u672f\u3002<\/p>\n<p>\u4e00\u3001\u539f\u7406<\/p>\n<p>1. \u6280\u672f\u57fa\u7840<\/p>\n<p>\u7f51\u9875\u5b89\u88c5App\u7684\u6280\u672f\u57fa\u7840\u662fProgressive Web Applications\uff08PWA\uff0c\u6e10\u8fdb\u5f0fWeb\u5e94\u7528\uff09\u3002PWA\u662f\u7531\u8c37\u6b4c\u63d0\u51fa\u7684\u4e00\u79cd\u65b0\u578bWeb\u5e94\u7528\u5f00\u53d1\u6a21\u5f0f\uff0c\u5b83\u7ed3\u5408\u4e86Web\u5e94\u7528\u7a0b\u5e8f\u548c\u539f\u751f\u79fb\u52a8\u5e94\u7528\u7684\u7279\u6027\u3002<\/p>\n<p>2. Service Worker<\/p>\n<p>PWA\u7684\u6838\u5fc3\u6280\u672f\u662fService Worker\u3002Service Worker\u662f\u4e00\u79cd\u8fd0\u884c\u5728\u6d4f\u89c8\u5668\u540e\u53f0\u7684\u72ec\u7acb\u811a\u672c\uff0c\u53ef\u4ee5\u5b9e\u73b0\u79bb\u7ebf\u7f13\u5b58\u3001\u6d88\u606f\u63a8\u9001\u3001\u540e\u53f0\u540c\u6b65\u7b49\u529f\u80fd\u3002\u501f\u52a9Service Worker\uff0cPWA\u53ef\u4ee5\u5b9e\u73b0\u5feb\u901f\u542f\u52a8\u3001\u79bb\u7ebf\u8bbf\u95ee\u3001\u6d88\u606f\u63a8\u9001\u7b49\u539f\u751f\u5e94\u7528\u7279\u6027\u3002<\/p>\n<p>3. \u7a0b\u5e8f\u6e05\u5355 (Manifest)<\/p>\n<p>\u4e3a\u4e86\u5b9e\u73b0\u5c06\u7f51\u9875\u5e94\u7528\u201c\u5b89\u88c5\u201d\u5230\u8bbe\u5907\u4e0a\uff0cPWA\u9700\u8981\u63d0\u4f9b\u4e00\u4e2a\u540d\u4e3aManifest\u7684JSON\u6587\u4ef6\u3002\u8be5\u6587\u4ef6\u5305\u542b\u4e86\u5e94\u7528\u7a0b\u5e8f\u7684\u4e00\u4e9b\u57fa\u672c\u4fe1\u606f\uff0c\u5982\u540d\u79f0\u3001\u56fe\u6807\u3001\u5c55\u793a\u65b9\u5f0f\u7b49\u3002\u501f\u52a9\u8fd9\u4e9b\u4fe1\u606f\uff0c\u6d4f\u89c8\u5668\u53ef\u4ee5\u5c06PWA\u6dfb\u52a0\u5230\u8bbe\u5907\u7684\u4e3b\u5c4f\u5e55\uff0c\u5e76\u4f5c\u4e3a\u4e00\u4e2a\u72ec\u7acb\u7684\u5e94\u7528\u7a0b\u5e8f\u8fd0\u884c\u3002<\/p>\n<p>4. Web App Banner<\/p>\n<p>\u5f53\u7528\u6237\u5728\u652f\u6301\u7684\u6d4f\u89c8\u5668\u4e2d\u8bbf\u95eePWA\u7f51\u7ad9\u65f6\uff0c\u6d4f\u89c8\u5668\u4f1a\u68c0\u6d4b\u5230Manifest\u6587\u4ef6\uff0c\u5e76\u663e\u793a\u4e00\u4e2aWeb App Banner\u3002\u7528\u6237\u53ef\u4ee5\u70b9\u51fb\u8fd9\u4e2a\u6a2a\u5e45\u6765\u5b89\u88c5PWA\u5e94\u7528\u3002\u8fd9\u901a\u5e38\u6bd4\u8bbf\u95ee\u5e94\u7528\u5546\u5e97\u66f4\u52a0\u65b9\u4fbf\u5feb\u6377\u3002<\/p>\n<p>\u4e8c\u3001\u5b9e\u73b0\u6b65\u9aa4<\/p>\n<p>1. \u521b\u5efa\u5e94\u7528\u7a0b\u5e8f\u6e05\u5355<\/p>\n<p>\u9996\u5148\uff0c\u9700\u8981\u4e3a\u7f51\u9875\u5e94\u7528\u521b\u5efa\u4e00\u4e2a\u540d\u4e3amanifest.json\u7684\u6587\u4ef6\uff0c\u8be5\u6587\u4ef6\u81f3\u5c11\u5305\u542b<a href=\"https:\/\/appfengzhuang.yimenapp.com\/app-87.html\">\u7f51\u7ad9\u5c01\u88c5\u6210\u5168\u5c4fapp<\/a>\u4e0b\u9762\u8fd9\u4e9b\u57fa\u672c\u4fe1\u606f\uff1a<\/p>\n<p>&#8220;`json<\/p>\n<p>{<\/p>\n<p>    &#8220;name&#8221;: &#8220;My App&#8221;,<\/p>\n<p>    &#8220;short_name&#8221;: &#8220;App&#8221;,<\/p>\n<p>    &#8220;description&#8221;: &#8220;A description of the app.&#8221;,<\/p>\n<p>    &#8220;start_url&#8221;: &#8220;\/index.html&#8221;,<\/p>\n<p>    &#8220;display&#8221;: &#8220;standalone&#8221;,<\/p>\n<p>    &#8220;background_color&#8221;: &#8220;#FFFFFF&#8221;,<\/p>\n<p>    &#8220;theme_color&#8221;: &#8220;#3F51B5&#8221;,<\/p>\n<p>    &#8220;icons&#8221;: [<\/p>\n<p>        {<\/p>\n<p>            &#8220;src&#8221;: &#8220;icon-192&#215;192.png&#8221;,<\/p>\n<p>            &#8220;sizes&#8221;: &#8220;192&#215;192&#8221;,<\/p>\n<p><figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/i.yimenyun.net\/2023-04\/07\/09\/31549993447.jpg\" \/><\/figure>\n<\/p>\n<p>            &#8220;type&#8221;: &#8220;image\/png&#8221;<\/p>\n<p>        },<\/p>\n<p>        {<\/p>\n<p>            &#8220;src&#8221;: &#8220;icon-512&#215;512.png&#8221;,<\/p>\n<p>            &#8220;sizes&#8221;: &#8220;512&#215;512&#8221;,<\/p>\n<p>            &#8220;type&#8221;: &#8220;image\/png&#8221;<\/p>\n<p>        }<\/p>\n<p>    ]<\/p>\n<p>}<\/p>\n<p>&#8220;`<\/p>\n<p>2. \u6ce8\u518cService Worker<\/p>\n<p>\u63a5\u4e0b\u6765\uff0c\u9700\u8981\u4e3a\u7f51\u9875\u5e94\u7528\u6ce8\u518c\u4e00\u4e2aService Worker\u3002\u5148\u521b\u5efa\u4e00\u4e2a\u540d\u4e3asw.js\u7684\u6587\u4ef6\uff0c\u7136\u540e\u5728\u7f51\u7ad9\u7684\u4e3b\u6587\u4ef6\uff08\u5982index.html\uff09\u4e2d\u6dfb\u52a0\u4ee5\u4e0b\u4ee3\u7801\uff1a<\/p>\n<p>&#8220;`javascript<\/p>\n<p>if (&#8216;serviceWorker&#8217; in navigator) {<\/p>\n<p>    navigator.serviceWorker.register(&#8216;\/sw.js&#8217;).then(function(registration) {<\/p>\n<p>        console.log(&#8216;Service Worker registered with scope:&#8217;, registration.scope);<\/p>\n<p>    }).cat<a href=\"https:\/\/appfengzhuang.yimenapp.com\/app-321.html\">\u4e00\u952e\u5c01\u88c5\u5b89\u5353app<\/a>ch(function(error) {<\/p>\n<p>        console.error(&#8216;Service Worker registration failed:&#8217;, error);<\/p>\n<p>    });<\/p>\n<p>}<\/p>\n<p>&#8220;`<\/p>\n<p>3. \u7f16\u5199Service Worker\u4ee3\u7801<\/p>\n<p>\u5728sw.js\u6587\u4ef6\u4e2d\uff0c\u7f16\u5199Service Worker\u7684\u4ee3\u7801\uff0c\u7528\u4e8e\u7f13\u5b58\u5e94\u7528\u7a0b\u5e8f\u7684\u8d44\u6e90\u3001\u5904\u7406\u6d88\u606f\u63a8\u9001\u7b49:<\/p>\n<p>&#8220;`javascript<\/p>\n<p>\/\/ Cache resources when Service Worker is installed<\/p>\n<p>self.addEventListener(&#8216;install&#8217;, function(event) {<\/p>\n<p>    \/\/ Code to cache resources<\/p>\n<p>});<\/p>\n<p>\/\/ Handle fetch events to serve cached resources or fetch from network<\/p>\n<p>self.addEventListener(&#8216;fetch&#8217;, function(event) {<\/p>\n<p>    \/\/ Code to serve cached resources or fetch from network<\/p>\n<p>});<\/p>\n<p>\/\/ Handle push notifications<\/p>\n<p>self.addEventListener(&#8216;push&#8217;, function(event) {<\/p>\n<p>    \/\/ Code to handle push notifications<\/p>\n<p>});<\/p>\n<p>&#8220;`<\/p>\n<p>4. \u5728\u7f51\u9875\u4e2d\u5f15\u7528\u7a0b\u5e8f\u6e05\u5355<\/p>\n<p>\u6700\u540e\uff0c\u5728\u7f51\u9875\u7684head\u5143\u7d20\u4e2d\u901a\u8fc7\u4ee5\u4e0b\u4ee3\u7801\u5f15\u7528manifest.json\u6587\u4ef6\uff1a<\/p>\n<p>&#8220;`html<\/p>\n<\/p>\n<p>&#8220;`<\/p>\n<p>\u81f3\u6b64\uff0c\u7f51\u9875\u5b89\u88c5App\u7684\u57fa\u672c\u5b9e\u73b0\u5df2\u7ecf\u5b8c\u6210\u3002\u7528\u6237\u8bbf\u95ee\u7f51\u7ad9\u65f6\uff0c\u6d4f\u89c8\u5668\u4f1a\u81ea\u52a8\u68c0\u6d4b\u5230PWA\u7279\u6027\uff0c\u5e76\u63d0\u793a\u5b89\u88c5\u3002<\/p>\n<p>\u4e09\u3001\u517c\u5bb9\u6027<\/p>\n<p>\u7531\u4e8e\u7f51\u9875\u5b89\u88c5App\u57fa\u4e8ePWA\u6280\u672f\uff0c\u56e0\u6b64\u517c\u5bb9\u6027\u4e3b\u8981\u53d6\u51b3\u4e8e\u6d4f\u89c8\u5668\u5bf9PWA\u7684\u652f\u6301\u7a0b\u5ea6\u3002\u76ee\u524d\uff0c\u5927\u90e8\u5206\u73b0\u4ee3\u6d4f\u89c8\u5668\u90fd\u5df2\u652f\u6301PWA\u7279\u6027\uff0c\u4f8b\u5982Chrome\u3001Firefox\u3001Safari\u7b49\u3002\u4f46\u5728\u4e00\u4e9b\u8f83\u8001\u7684\u6d4f\u89c8\u5668\u6216\u975e\u4e3b\u6d41\u6d4f\u89c8\u5668\u4e2d\uff0cPWA\u7279\u6027\u53ef\u80fd\u65e0\u6cd5\u6b63\u5e38\u4f7f\u7528\u3002<\/p>\n<p>\u603b\u4e4b\uff0c\u7f51\u9875\u5b89\u88c5App\u901a\u8fc7PWA\u6280\u672f\u5b9e\u73b0\uff0c\u5177\u5907\u4e86\u539f\u751f\u5e94\u7528\u7684\u7279\u6027\uff0c\u5e76\u4e3a\u7528\u6237\u548c\u5f00\u53d1\u8005\u63d0\u4f9b\u4e86\u4fbf\u5229\u3002\u5728\u5145\u5206\u8003\u8651\u517c\u5bb9\u6027\u7684\u524d\u63d0\u4e0b\uff0c\u5f00\u53d1\u8005\u53ef\u4ee5\u8003\u8651\u4f7f\u7528\u8fd9\u79cd\u65b9\u5f0f\u6765\u6269\u5c55\u81ea\u5df1\u7684\u5e94\u7528\u7a0b\u5e8f\u5206\u53d1\u6e20\u9053\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u7f51\u9875\u5b89\u88c5App\u662f\u4e00\u79cd\u63d0\u4f9b\u7ed9\u7528\u6237\u76f4\u63a5\u5728\u7f51\u9875\u4e0a\u4e0b\u8f7d\u548c\u5b89\u88c5\u79fb\u52a8\u5e94\u7528\u7a0b\u5e8f\u7684\u65b9\u5f0f\u3002\u8fd9\u79cd\u65b9\u5f0f\u8d8a\u6765\u8d8a\u53d7\u5230\u5f00\u53d1\u8005\u548c\u7528\u6237\u7684\u6b22\u8fce\uff0c\u56e0\u4e3a\u5b83\u7b80\u5316\u4e86\u7a0b\u5e8f\u7684\u5206\u53d1\u8fc7\u7a0b\uff0c\u7528\u6237\u65e0\u9700\u8bbf\u95ee\u5e94\u7528\u5546\u5e97\u5373\u53ef\u83b7\u5f97\u6240\u9700\u7684\u5e94\u7528\u7a0b\u5e8f\u3002\u672c\u6587\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u7f51<\/p>\n","protected":false},"author":15,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[15527,1775,755,1014,21261],"class_list":["post-32525","post","type-post","status-publish","format-standard","hentry","category-appkaifa","tag-iosapp","tag-1775","tag-755","tag-1014","tag-app"],"_links":{"self":[{"href":"https:\/\/app.applebyme.cn\/cloud\/wp-json\/wp\/v2\/posts\/32525","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/app.applebyme.cn\/cloud\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/app.applebyme.cn\/cloud\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/app.applebyme.cn\/cloud\/wp-json\/wp\/v2\/users\/15"}],"replies":[{"embeddable":true,"href":"https:\/\/app.applebyme.cn\/cloud\/wp-json\/wp\/v2\/comments?post=32525"}],"version-history":[{"count":1,"href":"https:\/\/app.applebyme.cn\/cloud\/wp-json\/wp\/v2\/posts\/32525\/revisions"}],"predecessor-version":[{"id":32778,"href":"https:\/\/app.applebyme.cn\/cloud\/wp-json\/wp\/v2\/posts\/32525\/revisions\/32778"}],"wp:attachment":[{"href":"https:\/\/app.applebyme.cn\/cloud\/wp-json\/wp\/v2\/media?parent=32525"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/app.applebyme.cn\/cloud\/wp-json\/wp\/v2\/categories?post=32525"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/app.applebyme.cn\/cloud\/wp-json\/wp\/v2\/tags?post=32525"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}