{"id":5215,"date":"2023-09-20T12:33:42","date_gmt":"2023-09-20T04:33:42","guid":{"rendered":"https:\/\/www.yimenyun.cn\/emen\/?p=5215"},"modified":"2023-09-20T12:33:42","modified_gmt":"2023-09-20T04:33:42","slug":"html5-%e6%89%93%e5%8c%85ios%e6%ad%a5%e9%aa%a4%e4%bb%8b%e7%bb%8d","status":"publish","type":"post","link":"https:\/\/www.yimenyun.cn\/emen\/5215\/","title":{"rendered":"html5 \u6253\u5305ios\u6b65\u9aa4\u4ecb\u7ecd"},"content":{"rendered":"

HTML5\u662f\u4e00\u79cd\u7528\u4e8e\u6784\u5efa\u7f51\u9875\u5185\u5bb9\u548c\u5e94\u7528\u7a0b\u5e8f\u7684\u6807\u51c6\u3002\u5b83\u6709\u8bb8\u591a\u4f18\u52bf\uff0c\u5982\u8de8\u5e73\u53f0\u6027\u3001\u6613\u4e8e\u5f00\u53d1\u548c\u7ef4\u62a4\u3001\u53ef\u8bbf\u95ee\u6027\u548c\u53ef\u6269\u5c55\u6027\u3002\u5728\u4e92\u8054\u7f51\u9886\u57df\uff0c\u4f7f\u7528HTML5\u6784\u5efa\u5e94\u7528\u7a0b\u5e8f\u5df2\u7ecf\u6210\u4e3a\u4e00\u79cd\u8d8b\u52bf\u3002\u7136\u800c\uff0c\u5bf9\u4e8e\u4e00\u4e9b\u9700\u8981\u53d1\u5e03\u5230iOS\u8bbe\u5907\u4e0a\u7684\u5e94\u7528\u7a0b\u5e8f\uff0c\u6253\u5305HTML5\u5e94\u7528\u7a0b\u5e8f\u53ef\u80fd\u4f1a\u9047\u5230\u4e00\u4e9b\u6311\u6218\u3002\u672c\u6587\u5c06\u4ecb\u7ecd\u5982\u4f55\u6253\u5305HTML5\u5e94\u7528\u7a0b\u5e8f\u4ee5\u5728iOS\u4e0a\u8fd0\u884c\u3002<\/p>\n

\u8981\u5728iOS\u4e0a\u8fd0\u884cHTML5\u5e94\u7528\u7a0b\u5e8f\uff0c\u6709\u4e24\u4e2a\u4e3b\u8981\u65b9\u6cd5\uff1a\u4f7f\u7528UIWebView\u548c\u4f7f\u7528Cordova\u3002<\/p>\n

1. \u4f7f\u7528UIWebView\uff1a<\/p>\n

UIWebView\u662fiOS\u4e0a\u7684\u4e00\u4e2a\u7c7b\uff0c\u53ef\u4ee5\u5728\u5e94\u7528\u7a0b\u5e8f\u4e2d\u5d4c\u5165\u7f51\u9875\u5185\u5bb9\u3002\u60a8\u53ef\u4ee5\u4f7f\u7528UIWebView\u6765\u52a0\u8f7dHTML5\u5e94\u7528\u7a0b\u5e8f\u5e76\u5728iOS\u8bbe\u5907\u4e0a\u8fd0\u884c\u3002\u4e0b\u9762\u662f\u4f7f\u7528UIWebView\u6253\u5305HTML5\u5e94\u7528\u7a0b\u5e8f\u7684\u6b65\u9aa4\uff1a<\/p>\n

\u7b2c\u4e00\u6b65\uff1a\u521b\u5efa\u4e00\u4e2a\u65b0\u7684Xcode\u9879\u76ee\u3002<\/p>\n

\u7b2c\u4e8c\u6b65\uff1a\u5c06HTML5\u6587\u4ef6\u6dfb\u52a0\u5230\u9879\u76ee\u4e2d\u3002\u53ef\u4ee5\u901a\u8fc7\u76f4\u63a5\u5c06\u6587\u4ef6\u62d6\u653e\u5230Xcode\u4e2d\u6765\u5b9e\u73b0\u3002<\/p>\n

\u7b2c\u4e09\u6b65\uff1a\u5728\u9879\u76ee\u7684ViewController\u4e2d\uff0c\u4f7f\u7528UIWebView\u52a0\u8f7dHios\u4e2d\u6253\u5305<\/a>TML5\u6587\u4ef6\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u7801\uff1a<\/p>\n

“`swift<\/p>\n

import UIKit<\/p>\n

class ViewController: UIViewController {<\/p>\n

@IBOutlet weak var webView: UIWebView!<\/p>\n<\/p>\n

override func viewDidLoad() {<\/p>\n

super.viewDidLoad()<\/p>\n<\/p>\n

if let htmlURL = Bundle.main.url(forResource: “index”, withExtension: “html”) {<\/p>\n

let htmlRequest = URLRequest(url: htmlURL)<\/p>\n

webView.loadRequest(htmlRequest)<\/p>\n

}<\/p>\n

}<\/p>\n

}<\/p>\n

“`<\/p>\n

\u7b2c\u56db\u6b65\uff1a\u6784\u5efa\u5e76\u8fd0\u884c\u5e94\u7528\u7a0b\u5e8f\u3002\u60a8\u7684HTML5\u5e94\u7528\u7a0b\u5e8f\u5c06\u5728\u6a21\u62df\u5668\u6216\u771f\u673a\u4e0a\u8fd0\u884c\u3002<\/p>\n

2. \u4f7f\u7528Cordova\uff1a<\/p>\n

Cordova\u662f\u4e00\u4e2a\u7528\u4e8e\u6784\u5efa\u79fb\u52a8\u5e94\u7528\u7a0b\u5e8f\u7684\u5f00\u6e90\u6846\u67b6\uff0c\u53ef\u4ee5\u4f7f\u7528HTML\u3001CSS\u548cJavaScript\u6784\u5efa\u8de8\u5e73\u53f0\u5e94\u7528\u7a0b\u5e8f\u3002Cordova\u63d0\u4f9b\u4e86\u4e00\u7ec4API\uff0c\u53ef\u4ee5\u901a\u8fc7JavaScript\u8bbf\u95ee\u8bbe\u5907\u529f\u80fd\uff0c\u4f8b\u5982\u6444\u50cf\u5934\u3001\u52a0\u901f\u5ea6\u8ba1\u548c\u6587\u4ef6\u7cfb\u7edf\u3002\u4e0b\u9762\u662f\u4f7f\u7528Cordova\u6253\u5305HTML5\u5e94\u7528\u7a0b\u5e8f\u7684\u6b65\u9aa4\uff1a<\/p>\n

\u7b2c\u4e00\u6b65\uff1a\u5b89\u88c5Cordova\u3002\u60a8\u53ef\u4ee5\u5728\u7ec8\u7aef\u4e2d\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u6765\u5b89\u88c5Cordova\uff1a<\/p>\n

“`shell<\/p>\n

npm install -g cordova<\/p>\n

“`<\/p>\n

\u7b2c\u4e8c\u6b65\uff1a\u521b\u5efa\u4e00\u4e2a\u65b0\u7684Cordova\u9879\u76ee\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n

“`shell<\/p>\n

cordova create MyApp com.example.myapp MyApp<\/p>\n

“`<\/p>\n

\u7b2c\u4e09\u6b65\uff1a\u5c06HTML5\u6587\u4ef6\u590d\u5236\u5230Cordova\u9879\u76ee\u7684www\u6587\u4ef6\u5939\u4e2d\u3002<\/p>\n

\u7b2c\u56db\u6b65\uff1a\u6dfb\u52a0iOS\u5e73\u53f0\u5230Cordova\u9879\u76ee\u4e2d\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n

“`shell<\/p>\n

cordova pweb\u6253\u5305ios\u4e0a\u67b6<\/a><\/p>\n

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

latform add ios<\/p>\n

“`<\/p>\n

\u7b2c\u4e94\u6b65\uff1a\u6784\u5efa\u5e76\u8fd0\u884c\u5e94\u7528\u7a0b\u5e8f\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n

“`shell<\/p>\n

cordova run ios<\/p>\n

“`<\/p>\n

\u60a8\u7684HTML5\u5e94\u7528\u7a0b\u5e8f\u5c06\u5728\u6a21\u62df\u5668\u6216\u771f\u673a\u4e0a\u8fd0\u884c\u3002<\/p>\n

\u4ee5\u4e0a\u662f\u5728iOS\u4e0a\u6253\u5305HTML5\u5e94\u7528\u7a0b\u5e8f\u7684\u4e24\u79cd\u65b9\u6cd5\u3002\u65e0\u8bba\u60a8\u9009\u62e9\u54ea\u79cd\u65b9\u6cd5\uff0c\u90fd\u53ef\u4ee5\u5c06\u60a8\u7684HTML5\u5e94\u7528\u7a0b\u5e8f\u6253\u5305\u6210\u4e00\u4e2a\u539f\u751fiOS\u5e94\u7528\u7a0b\u5e8f\uff0c\u5e76\u53d1\u5e03\u5230App Store\u4e0a\u3002\u6240\u4ee5\uff0c\u65e0\u8bba\u60a8\u662f\u4e2a\u4eba\u5f00\u53d1\u8005\u8fd8\u662f\u4f01\u4e1a\u5f00\u53d1\u8005\uff0c\u8fd9\u4e9b\u65b9\u6cd5\u90fd\u5c06\u5e2e\u52a9\u60a8\u5c06HTML5\u5e94\u7528\u7a0b\u5e8f\u53d1\u5e03\u5230iOS\u8bbe\u5907\u4e0a\u3002\u5e0c\u671b\u672c\u6587\u5bf9\u60a8\u6709\u6240\u5e2e\u52a9\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"

HTML5\u662f\u4e00\u79cd\u7528\u4e8e\u6784\u5efa\u7f51\u9875\u5185\u5bb9\u548c\u5e94\u7528\u7a0b\u5e8f\u7684\u6807\u51c6\u3002\u5b83\u6709\u8bb8\u591a\u4f18\u52bf\uff0c\u5982\u8de8\u5e73\u53f0\u6027\u3001\u6613\u4e8e\u5f00\u53d1\u548c\u7ef4\u62a4\u3001\u53ef\u8bbf\u95ee\u6027\u548c\u53ef\u6269\u5c55\u6027\u3002\u5728\u4e92\u8054\u7f51\u9886\u57df\uff0c\u4f7f\u7528HTML5\u6784\u5efa\u5e94\u7528\u7a0b\u5e8f\u5df2\u7ecf\u6210\u4e3a\u4e00\u79cd\u8d8b\u52bf\u3002\u7136\u800c\uff0c\u5bf9\u4e8e\u4e00\u4e9b\u9700\u8981\u53d1\u5e03\u5230iO<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[9827,366,9826,12,23],"topic":[],"class_list":["post-5215","post","type-post","status-publish","format-standard","hentry","category-appkf","tag-ios","tag-366","tag-iosapp","tag-12","tag-23"],"_links":{"self":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/posts\/5215","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\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/comments?post=5215"}],"version-history":[{"count":0,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/posts\/5215\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/media?parent=5215"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/categories?post=5215"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/tags?post=5215"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/topic?post=5215"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}