{"id":11267,"date":"2023-12-05T18:33:50","date_gmt":"2023-12-05T10:33:50","guid":{"rendered":"https:\/\/www.yimenyun.cn\/emen\/?p=11267"},"modified":"2023-12-05T18:33:50","modified_gmt":"2023-12-05T10:33:50","slug":"%e6%80%8e%e4%b9%88%e5%b0%86h5%e7%94%9f%e6%88%90app","status":"publish","type":"post","link":"https:\/\/www.yimenyun.cn\/emen\/11267\/","title":{"rendered":"\u600e\u4e48\u5c06h5\u751f\u6210app?"},"content":{"rendered":"

\u5c06H5\u751f\u6210APP\u6307\u7684\u662f\uff0c\u5c06\u57fa\u4e8eHTML5\u3001CSS3\u548cJavaScript\u7684\u79fb\u52a8Web\u5e94\u7528\u8f6c\u6362\u4e3a\u539f\u751f\u5e94\u7528\u6216\u8005\u6df7\u5408\u5e94\u7528\u3002H5\u5e94\u7528\u5728\u79fb\u52a8\u8bbe\u5907\u4e0a\u53ef\u4ee5\u901a\u8fc7\u6d4f\u89c8\u5668\u76f4\u63a5\u8fd0\u884c\uff0c\u800c\u539f\u751f\u5e94\u7528\u9700\u8981\u5728\u4e0d\u540c\u7684\u64cd\u4f5c\u7cfb\u7edf\u4e0a\u8fdb\u884c\u5355\u72ec\u5f00\u53d1\u3002\u5c06H5\u5e94\u7528\u751f\u6210APP\u53ef\u4ee5\u4e3a\u7528\u6237\u63d0\u4f9b\u66f4\u597d\u7684\u4f53\u9a8c\uff0c\u5e76\u5229\u7528\u539f\u751f\u529f\u80fd\uff08\u5982\u6444\u50cf\u5934\u3001\u5b9a\u4f4d\u7b49\uff09\u6765\u4e30\u5bcc\u5e94\u7528\u7684\u529f\u80fd\u3002<\/p>\n

\u4e0b\u9762\u6211\u4eec\u8be6\u7ec6\u4ecb\u7ecd\u4e00\u4e0b\u5c06H5\u751f\u6210APP\u7684\u4e24\u79cd\u4e3b\u8981\u65b9\u5f0f\uff1aWebView\u548c\u6df7\u5408\u5e94\u7528\u6846\u67b6\u3002<\/p>\n

1. WebView\uff1a<\/p>\n

WebView\u662f\u4e00\u4e2a\u5728\u5e94\u7528\u4e2d\u5d4c\u5165\u7684\u6d4f\u89c8\u5668\u63a7\u4ef6\uff0c\u7528\u4e8e\u52a0\u8f7d\u548c\u663e\u793a\u7f51\u9875\u5185\u5bb9\u3002\u4e3a\u4e86\u5c06H5\u751f\u6210APP\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u539f\u751f\u5f00\u53d1\u5de5\u5177\uff08\u5982Android Studio\u6216Xcode\uff09\u521b\u5efa\u4e00\u4e2a\u65b0\u7684APP\uff0c\u7136\u540e\u5728APP\u4e2d\u5d4c\u5165\u4e00\u4e2a\u5168\u5c4f\u7684WebView\u7ec4\u4ef6\u3002<\/p>\n

\u5177\u4f53\u6b65\u9aa4\u5982\u4e0b\uff1a<\/p>\n

\u5bf9\u4e8eAndroid\uff1a<\/p>\n

a. \u6253\u5f00Android Studio\u5e76\u521b\u7f51\u9875\u4e00\u952e\u751f\u6210app\u5e73\u53f0<\/a>\u5efa\u4e00\u4e2a\u65b0\u7684\u9879\u76ee\u3002<\/p>\n

b. \u5728activity_main.xml\u5e03\u5c40\u6587\u4ef6\u4e2d\u6dfb\u52a0\u4e00\u4e2aWebView\u7ec4\u4ef6\uff0c\u5e76\u8bbe\u7f6e\u5176\u5bbd\u9ad8\u5c5e\u6027\u4e3amatch_parent\u3002<\/p>\n

c. \u5728MainActivity.java\u6587\u4ef6\u4e2d\uff0c\u521d\u59cb\u5316WebView\u7ec4\u4ef6\uff0c\u5e76\u8bbe\u7f6e\u5176\u52a0\u8f7dH5\u9875\u9762\u7684URL\u3002<\/p>\n

\u5bf9\u4e8eiOS\uff1a<\/p>\n

a. \u6253\u5f00Xcode\u5e76\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u9879\u76ee\u3002<\/p>\n

b. \u5728Main.storyboard\u4e2d\u6dfb\u52a0\u4e00\u4e2aWKWebView\u7ec4\u4ef6\uff0c\u5e76\u8bbe\u7f6e\u5176AutoLayout\u7ea6\u675f\u4ee5\u586b\u5145\u6574\u4e2a\u5c4f\u5e55\u3002<\/p>\n

c. \u5728ViewController.swift\u6587\u4ef6\u4e2d\uff0c\u521d\u59cb\u5316WKWebView\u7ec4\u4ef6\uff0c\u5e76\u8bbe\u7f6e\u5176\u52a0\u8f7dH5\u9875\u9762\u7684URL\u3002<\/p>\n

2. \u6df7\u5408\u5e94\u7528\u6846\u67b6\uff1a<\/p>\n

\u6df7\u5408\u5e94\u7528\u6846\u67b6\u662f\u4e00\u79cd\u5f00\u53d1\u5de5\u5177\uff0c\u7528\u4e8e\u5c06H5\u5e94\u7528\u8f6c\u6362\u4e3a\u8de8\u5e73\u53f0\u7684\u539f\u751f\u5e94\u7528\uff0c\u5e38\u89c1\u7684\u6df7\u5408\u5e94\u7528\u6846\u67b6\u6709Cordova\u3001Ionic\u3001React Native\u7b49\u3002\u5176\u4e2d\u524d\u4e24\u8005\u4f7f\u7528Web\u6280\u672f\u8fdb\u884cUI\u5c55\u793a\uff0c\u540e\u8005\u4f7f\u7528\u539f\u751f\u7ec4\u4ef6\u8fdb\u884cUI\u5c55\u793a\u3002<\/p>\n

\u4ee5Cordova\u4e3a\u4f8b\uff0c\u4e0b\u9762\u4ecb\u7ecd\u5982\u4f55\u5c06H5\u751f\u6210APP\uff1a<\/p>\n

a. \u5b89\u88c5Node.js\u548cCordova CLI\u3002<\/p>\n

b. \u4f7f\u7528`cordova create`\u547d\u4ee4\u521b\u5efa\u4e00\u4e2a\u65b0\u7684Cordova\u9879\u76ee\u3002<\/p>\n

c. \u5728\u9879\u76ee\u7684`www`\u76ee\u5f55\u4e2d\uff0c\u653e\u7f6e\u60a8\u7684H5\u5e94\u7528\u6587\u4ef6\uff08\u4f8b\u5982\uff1aindex.html\uff0cCSS\u6587\u4ef6\u548cJavaScript\u6587\u4ef6\uff09\u3002<\/p>\n

d. \u4f7f\u7528`cordova platform add`\u547d\u4ee4\u6dfb\u52a0\u9700\u8981<\/p>\n

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

\u652f\u6301\u7684\u76ee\u6807\u5e73\u53f0\uff08\u5982\uff1aandroid\u6216ios\uff09\u3002<\/p>\n

e. \u4f7f\u7528`cordova plugin add`\u547d\u4ee4\u5b89\u88c5\u6240\u9700\u7684\u539f\u751f\u63d2\u4ef6\uff08\u5982\uff1acamera\u3001geolocation\u7b49\uff09\u3002<\/p>\n

f. \u4f7f\u7528`cordova build`\u547d\u4ee4\u6784\u5efa\u9879\u76ee\uff0c\u751f\u6210\u5177\u6709\u5d4c\u5165WebView\u7684\u539f\u751fAPP\u3002<\/p>\n

\u9009\u62e9\u54ea\u79cd\u65b9\u5f0f\u53d6\u51b3\u4e8e\u60a8\u7684\u9700\u6c42\u548c\u6280\u672f\u80fd\u529b\u3002\u5bf9\u4e8e\u4ec5\u4ec5\u9700\u8981\u5c06H5\u5e94\u7528\u7b80\u5355\u5305\u88c5\u4e3aAPP\u7684\u9879\u76ee\uff0c\u53ef\u4ee5\u4f7f\u7528WebView\u65b9\u5f0f\uff1b\u800c\u5bf9\u4e8e\u9700\u8981\u8de8\u5e73\u53f0\u652f\u6301\u3001\u7f51\u7ad9app\u751f\u6210\u5668\u8f6f\u4ef6<\/a>\u66f4\u4e30\u5bcc\u7684\u539f\u751f\u529f\u80fd\u548c\u66f4\u9ad8\u7684\u5f00\u53d1\u6548\u7387\u7684\u9879\u76ee\uff0c\u63a8\u8350\u4f7f\u7528\u6df7\u5408\u5e94\u7528\u6846\u67b6\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

\u5c06H5\u751f\u6210APP\u6307\u7684\u662f\uff0c\u5c06\u57fa\u4e8eHTML5\u3001CSS3\u548cJavaScript\u7684\u79fb\u52a8Web\u5e94\u7528\u8f6c\u6362\u4e3a\u539f\u751f\u5e94\u7528\u6216\u8005\u6df7\u5408\u5e94\u7528\u3002H5\u5e94\u7528\u5728\u79fb\u52a8\u8bbe\u5907\u4e0a\u53ef\u4ee5\u901a\u8fc7\u6d4f\u89c8\u5668\u76f4\u63a5\u8fd0\u884c\uff0c\u800c\u539f\u751f\u5e94\u7528\u9700\u8981\u5728\u4e0d\u540c\u7684\u64cd\u4f5c\u7cfb\u7edf\u4e0a\u8fdb\u884c\u5355<\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[16814,16,16815,736,23],"topic":[],"class_list":{"0":"post-11267","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"hentry","6":"category-appkf","7":"tag-app","8":"tag-16","10":"tag-736","11":"tag-23"},"_links":{"self":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/posts\/11267","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\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/comments?post=11267"}],"version-history":[{"count":1,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/posts\/11267\/revisions"}],"predecessor-version":[{"id":11373,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/posts\/11267\/revisions\/11373"}],"wp:attachment":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/media?parent=11267"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/categories?post=11267"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/tags?post=11267"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/topic?post=11267"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}