{"id":4537,"date":"2023-09-08T15:32:14","date_gmt":"2023-09-08T07:32:14","guid":{"rendered":"https:\/\/www.yimenyun.cn\/emen\/?p=4537"},"modified":"2023-09-08T15:32:14","modified_gmt":"2023-09-08T07:32:14","slug":"%e5%9c%a8%e7%ba%bf%e6%89%93%e5%8c%85%e7%bd%91%e9%a1%b5%e5%ba%94%e7%94%a8%e6%93%8d%e4%bd%9c%e6%b5%81%e7%a8%8b%e4%bb%8b%e7%bb%8d","status":"publish","type":"post","link":"https:\/\/www.yimenyun.cn\/emen\/4537\/","title":{"rendered":"\u5728\u7ebf\u6253\u5305\u7f51\u9875\u5e94\u7528\u64cd\u4f5c\u6d41\u7a0b\u4ecb\u7ecd"},"content":{"rendered":"

\u5728\u7ebf\u6253\u5305\u7f51\u9875\u5e94\u7528\u6307\u7684\u662f\u5c06\u7f51\u9875\u5185\u5bb9\u5c01\u88c5\u6210\u4e00\u4e2a\u72ec\u7acb\u7684\u5e94\u7528\u7a0b\u5e8f\uff0c\u4f7f\u7528\u6237\u80fd\u591f\u5728\u5404\u79cd\u8bbe\u5907\u4e0a\u8bbf\u95ee\u5e76\u8fdb\u884c\u64cd\u4f5c\uff0c\u800c\u65e0\u9700\u4f7f\u7528\u4f20\u7edf\u7684\u6d4f\u89c8\u5668\u3002\u8fd9\u4e2a\u8fc7\u7a0b\u9700\u8981\u5bf9\u7f51\u9875\u8fdb\u884c\u4e00\u4e9b\u8c03\u6574\u548c\u4f18\u5316\uff0c\u4f7f\u5176\u66f4\u7b26\u5408\u672c\u5730\u5e94\u7528\u7a0b\u5e8f\u7684\u4ea4\u4e92\u548c\u754c\u9762\u8bbe\u8ba1\u3002\u672c\u6587\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5728\u7ebf\u6253\u5305\u7f51\u9875\u5e94\u7528\u7684\u539f\u7406\u548c\u65b9\u6cd5\uff0c\u5e2e\u52a9\u60a8\u66f4\u597d\u5730\u7406\u89e3\u8fd9\u4e2a\u6982\u5ff5\u3002<\/p>\n

\u4e00\u3001\u539f\u7406\u4ecb\u7ecd<\/p>\n

\u5728\u7ebf\u6253\u5305\u7f51\u9875\u5e94\u7528\u7684\u539f\u7406\u4e3b\u8981\u4f9d\u8d56\u4e8e\u4e24\u4e2a\u5173\u952e\u6280\u672f\uff1aWebView \u548c Web App Manifest\u3002WebView \u662f\u4e00\u79cd\u5d4c\u5165\u5f0f\u6d4f\u89c8\u5668\u7ec4\u4ef6\uff0c\u5b83\u5141\u8bb8\u5f00\u53d1\u8005\u5c06\u7f51\u9875\u5185\u5bb9\u5d4c\u5165\u5230\u539f\u751f\u5e94\u7528\u4e2d\u3002\u800c Web App Manifest \u662f\u4e00\u79cd\u7528\u4e8e\u63cf\u8ff0\u7f51\u9875\u5e94\u7528\u4fe1\u606f\u7684 JSON \u6587\u4ef6\uff0c\u5b83\u53ef\u4ee5\u5e2e\u52a9\u7528\u6237\u5c06\u7f51\u9875\u5e94\u7528\u6dfb\u52a0\u5230\u684c\u9762\u6216\u79fb\u52a8\u8bbe\u5907\u7684\u4e3b\u5c4f\u5e55\u4e0a\u3002\u901a\u8fc7\u8fd9\u4e24\u4e2a\u6280\u672f\uff0c\u5f00\u53d1\u8005\u53ef\u4ee5\u5c06\u7f51\u9875\u8f6c\u6362\u4e3a\u5177\u6709\u5e94\u7528\u7a0b\u5e8f\u7279\u6027\u7684\u7f51\u9875\u5e94\u7528\uff08\u4e5f\u79f0\u4f5c PWA\uff0cProgressive Web App\uff09\u3002<\/p>\n

\u4e8c\u3001\u8be6\u7ec6\u4ecb\u7ecd\u548c\u5b9e\u8df5<\/p>\n

\u8981\u6210\u529f\u5730\u6253\u5305\u7f51\u9875\u5e94\u7528\uff0c\u60a8\u9700\u8981\u9075\u5faa\u4ee5\u4e0b\u5173\u952e\u6b65\u9aa4\uff1a<\/p>\n

1. \u51c6\u5907\u7f51\u9875\u5185\u5bb9<\/p>\n

\u9996\u5148\uff0c\u60a8\u9700\u8981\u4e3a\u60a8\u7684\u7f51\u9875\u5e94\u7528\u51c6\u5907\u5408\u9002\u7684\u5185\u5bb9\u3002\u8fd9\u5305\u62ec\u8bbe\u8ba1\u4e00\u4e2a\u9002\u5e94\u4e0d\u540c\u8bbe\u5907\u7684\u54cd\u5e94\u5f0f\u5e03\u5c40\uff0c\u4ee5\u53ca\u9075\u5faa\u4e00\u5b9a\u7684\u8bbe\u8ba1\u6307\u5357\u6765\u63d0\u4f9b\u66f4\u597d\u7684\u7528\u6237\u4f53\u9a8c\u3002<\/p>\n

2. \u521b\u5efa Web App Manifest<\/p>\n

\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a manifest.json \u7684\u6587\u4ef6\uff0c\u5e76\u5728\u8be5\u6587\u4ef6\u4e2d\u5b9a\u4e49\u60a8\u7684\u7f51\u9875\u5e94\u7528\u7684\u4fe1\u606f\u3002\u5305\u62ec\u5e94\u7528\u540d\u3001\u56fe\u6807\u3001\u4e3b\u9898\u989c\u8272\u7b49\u3002\u60a8\u8fd8\u53ef\u4ee5\u4e3a\u7f51\u9875\u5e94\u7528\u6dfb\u52a0\u7b80\u4ecb\u548c\u5173\u952e\u5b57\u7b49\u5185\u5bb9\uff0c\u4ee5\u4fbf\u4e8e\u641c\u7d22\u5f15\u64ce\u6536\u5f55\u3002\u4f8b\u5982\uff1a<\/p>\n

“`json<\/p>\n

{<\/p>\n

“name”: “\u6211\u7684\u5728\u7ebf\u6253\u5305\u7f51\u9875\u5e94\u7528”,<\/p>\n

“short_name”: “\u7f51\u9875\u5e94\u7528”,<\/p>\n

“description”: “\u4e00\u4e2a\u7b80\u5355\u7684\u5728\u7ebf\u6253\u5305\u7f51\u9875\u5e94\u7528\u793a\u4f8b\u3002”,<\/p>\n

“start_url”: “\/”,<\/p>\n

“display”: “standalone”,<\/p>\n

“background_color”: “#ffffff”,<\/p>\n

“theme_color”: “#000000”,<\/p>\n

“icons”: [<\/p>\n

{<\/p>\n

“src”: “\/icon-192.png”,<\/p>\n

“sizes”: “192×192”,<\/p>\n

“type”: “image\/png”<\/p>\n

},<\/p>\n

{<\/p>\n

“src”: “\/icon-512.png”,<\/p>\n

“sizes”: “512×512”,<\/p>\n

“type”: “image\/png”<\/p>\n

}<\/p>\n

]<\/p>\n

}<\/p>\n

“`<\/p>\n

3. \u5728\u7f51\u9875\u4e2d\u5f15\u7528 Web App Manifest<\/p>\n

\u5728\u60a8\u7684 HTML \u9875\u9762\u4e2d\u7684 “ \u6807\u7b7e\u5185\u6dfb\u52a0\u5982\u4e0b\u4ee3\u7801\uff0c\u5f15\u7528 m\u5b89\u5353app\u7f51\u9875\u5c01\u88c5<\/a>anifest.json \u6587\u4ef6\uff1a<\/p>\n

“`html<\/p>\n<\/p>\n

“`<\/p>\n

4. \u914d\u7f6e\u670d\u52a1\u5de5\u4f5c\u7ebf\u7a0b\uff08Service Worker\uff09<\/p>\n

\u670d\u52a1\u5de5\u4f5c\u7ebf\u7a0b\uff08Service Worker\uff09\u662f\u4e00\u79cd\u8fd0\u884c\u5728\u6d4f\u89c8\u5668\u540e\u53f0\u7684\u811a\u672c\uff0c\u5b83\u53ef\u4ee5\u5e2e\u52a9\u60a8\u5904\u7406\u79bb\u7ebf\u8bbf\u95ee\u3001\u6570\u636e\u7f13\u5b58\u7b49\u95ee\u9898\u3002\u4e3a\u60a8\u7684\u7f51\u9875\u5e94\u7528\u521b\u5efa\u4e00\u4e2a\u670d\u52a1\u5de5\u4f5c\u7ebf\u7a0b\u5e76\u5c06\u5176\u6ce8\u518c\u3002<\/p>\n

“`javascript<\/p>\n

\/\/ \u521b\u5efa service-worker.js \u6587\u4ef6<\/p>\n

self.addEventListener(‘install’, (event) => {<\/p>\n

\/\/ \u5728\u8fd9\u91cc\u8fdb\u884c\u9884\u7f13\u5b58\u64cd\u4f5c<\/p>\n

});<\/p>\n

self.addEventListener(‘fetch’, (event) => {<\/p>\n

\/\/ \u5728\u8fd9\u91cc\u8fdb\u884c\u7f13\u5b58\u7b56\u7565\u5904\u7406<\/p>\n

});<\/p>\n

\/\/ \u5728 HTML \u9875\u9762\u5f15\u5165 service-worker.js \u5e76\u6ce8\u518c<\/p>\n

if (‘serviceWorker’ in navigator) {<\/p>\n

navigator.serviceW<\/p>\n

<\/figure>\n<\/p>\n

orker.register(‘\/service-worker.js’);<\/p>\n

}<\/p>\n

“`<\/p>\n

5.\u6d4b\u8bd5\u548c\u4f18\u5316<\/p>\n

\u5728\u5b8c\u6210\u4e0a\u8ff0\u6b65\u9aa4\u540e\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u6d4f\u89c8\u5668\u7684\u5f00\u53d1\u8005\u5de5\u5177\u8fdb\u884c\u6d4b\u8bd5\u548c\u8c03\u8bd5\u3002\u67e5\u770b\u5e94\u7528\u7a0b\u5e8f\u662f\u5426\u6210\u529f\u6ce8\u518c Service Worker\uff0capp\u5957\u58f3<\/a>\u662f\u5426\u663e\u793a\u6b63\u786e\u7684 PWA \u7279\u6027\uff08\u5982\u6dfb\u52a0\u5230\u4e3b\u5c4f\u5e55\u7b49\uff09\u3002\u5982\u679c\u51fa\u73b0\u95ee\u9898\uff0c\u8bf7\u68c0\u67e5\u4ee3\u7801\u5e76\u4f18\u5316\u3002<\/p>\n

\u603b\u7ed3<\/p>\n

\u5728\u7ebf\u6253\u5305\u7f51\u9875\u5e94\u7528\u53ef\u4ee5\u5e2e\u52a9\u60a8\u5c06\u7f51\u9875\u5185\u5bb9\u5c01\u88c5\u6210\u5177\u6709\u539f\u751f\u5e94\u7528\u7279\u6027\u7684\u7f51\u9875\u5e94\u7528\u3002\u901a\u8fc7\u4f7f\u7528 WebView\u3001Web App Manifest \u548c\u670d\u52a1\u5de5\u4f5c\u7ebf\u7a0b\u7b49\u6280\u672f\uff0c\u60a8\u53ef\u4ee5\u4f18\u5316\u7f51\u9875\u5e94\u7528\u7684\u6027\u80fd\u5e76\u63d0\u4f9b\u66f4\u597d\u7684\u7528\u6237\u4f53\u9a8c\u3002\u5728\u5b9e\u8df5\u4e2d\uff0c\u8bf7\u6ce8\u610f\u9075\u5faa\u76f8\u5173\u6307\u5bfc\u539f\u5219\uff0c\u5e76\u59cb\u7ec8\u5bf9\u60a8\u7684\u7f51\u9875\u5e94\u7528\u8fdb\u884c\u6d4b\u8bd5\u548c\u4f18\u5316\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

\u5728\u7ebf\u6253\u5305\u7f51\u9875\u5e94\u7528\u6307\u7684\u662f\u5c06\u7f51\u9875\u5185\u5bb9\u5c01\u88c5\u6210\u4e00\u4e2a\u72ec\u7acb\u7684\u5e94\u7528\u7a0b\u5e8f\uff0c\u4f7f\u7528\u6237\u80fd\u591f\u5728\u5404\u79cd\u8bbe\u5907\u4e0a\u8bbf\u95ee\u5e76\u8fdb\u884c\u64cd\u4f5c\uff0c\u800c\u65e0\u9700\u4f7f\u7528\u4f20\u7edf\u7684\u6d4f\u89c8\u5668\u3002\u8fd9\u4e2a\u8fc7\u7a0b\u9700\u8981\u5bf9\u7f51\u9875\u8fdb\u884c\u4e00\u4e9b\u8c03\u6574\u548c\u4f18\u5316\uff0c\u4f7f\u5176\u66f4\u7b26\u5408\u672c\u5730\u5e94\u7528\u7a0b\u5e8f\u7684\u4ea4\u4e92\u548c\u754c\u9762\u8bbe\u8ba1\u3002<\/p>\n","protected":false},"author":22,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[8775,8774,291,251,149],"topic":[],"class_list":["post-4537","post","type-post","status-publish","format-standard","hentry","category-appkf","tag-app","tag-8774","tag-291","tag-251","tag-149"],"_links":{"self":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/posts\/4537","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/users\/22"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/comments?post=4537"}],"version-history":[{"count":0,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/posts\/4537\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/media?parent=4537"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/categories?post=4537"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/tags?post=4537"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/topic?post=4537"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}