{"id":13500,"date":"2023-12-01T17:50:15","date_gmt":"2023-12-01T09:50:15","guid":{"rendered":"https:\/\/h5app.yimenapp.cn\/h5app\/?p=13500"},"modified":"2023-12-01T17:50:15","modified_gmt":"2023-12-01T09:50:15","slug":"iosapp%e5%a5%97h5%e8%a6%81%e6%80%8e%e4%b9%88%e5%81%9a%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/h5app.yimenapp.cn\/h5app\/2023\/sjapp\/13500\/","title":{"rendered":"iosapp\u5957h5\u8981\u600e\u4e48\u505a\uff1f"},"content":{"rendered":"<p>iOS\u5e94\u7528\u7a0b\u5e8f\u53ef\u4ee5\u96c6\u6210\u7f51\u9875\u6d4f\u89c8\u5668\uff0c\u4ee5\u4fbf\u76f4\u63a5\u5728\u5e94\u7528\u7a0b\u5e8f\u4e2d\u52a0\u8f7d\u7f51\u9875\u3002\u8fd9\u79cd\u96c6\u6210\u65b9\u5f0f\u88ab\u79f0\u4e3a\u5c06H5\u5d4c\u5165iOS\u5e94\u7528\u7a0b\u5e8f\u4e2d\u3002\u5c06H5\u5d4c\u5165iOS\u5e94\u7528\u7a0b\u5e8f\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u5e94\u7528\u7a0b\u5e8f\u66f4\u52a0\u4e30\u5bcc\u591a\u5f69\uff0c\u589e\u52a0\u7528\u6237\u4f53\u9a8c\u548c\u4ea4\u4e92\u6027\u3002\u4e0b\u9762\u662fiOS\u5e94\u7528\u7a0b\u5e8f\u4e2d\u5c06H5\u5d4c\u5165\u7684\u539f\u7406\u548c\u8be6\u7ec6\u4ecb\u7ecd\u3002<\/p>\n<p>\u4e00\u3001\u539f\u7406<\/p>\n<p>\u5c06H5\u5d4c\u5165iOS\u5e94\u7528\u7a0b\u5e8f\u4e2d\uff0c\u9700\u8981\u4f7f\u7528UIWebView\u6216WKWebView\u3002\u8fd9\u4e24\u4e2a\u7ec4\u4ef6\u90fd\u53ef\u4ee5\u7528\u4e8e\u5728\u5e94\u7528\u7a0b\u5e8f\u4e2d\u52a0\u8f7d\u7f51\u9875\u3002UIWebView\u662fiOS 2.0\u4e2d\u5f15\u5165\u7684\uff0c\u5b83\u662f\u4e00\u4e2a\u57fa\u4e8eWebKit\u5f15\u64ce\u7684\u7f51\u9875\u6d4f\u89c8\u5668\u3002WKWebView\u662fiOS 8.0\u4e2d\u5f15\u5165\u7684\uff0c\u5b83\u662f\u4e00\u4e2a\u57fa\u4e8eWebKit\u5f15\u64ce\u7684\u73b0\u4ee3\u5316\u7f51\u9875\u6d4f\u89c8\u5668\uff0c\u5177\u6709\u66f4\u597d\u7684\u6027\u80fd\u548c\u66f4\u591a\u7684\u529f\u80fd\u3002<\/p>\n<p>\u5c06H5\u5d4c\u5165iOS\u5e94\u7528\u7a0b\u5e8f\u4e2d\u7684\u8fc7\u7a0b\u5982\u4e0b\uff1a<\/p>\n<p>1.\u521b\u5efaUIWebView\u6216WKWebView\u7ec4\u4ef6\uff1b<\/p>\n<p>2.\u5c06UIWebView\u6216WKWebView\u7ec4\u4ef6\u6dfb\u52a0\u5230\u5e94\u7528\u7a0b\u5e8f\u7684\u89c6\u56fe\u5c42\u6b21\u7ed3\u6784\u4e2d\uff1b<\/p>\n<p>3.\u52a0\u8f7dH5\u9875\u9762\uff1b<\/p>\n<p><a href=\"https:\/\/appdabao.yimenapp.com\/jiage-1386.html\">\u8f6f\u4ef6\u6253\u5305\u53d1\u5e03<\/a><\/p>\n<p>4.\u5728\u5e94\u7528\u7a0b\u5e8f\u4e2d\u5904\u7406H5\u9875\u9762\u7684\u4e8b\u4ef6\u548c\u4ea4\u4e92\u3002<\/p>\n<p>\u4e8c\u3001\u8be6\u7ec6\u4ecb\u7ecd<\/p>\n<p>1.\u521b\u5efaUIWebView\u6216WKWebView\u7ec4\u4ef6<\/p>\n<p>\u5728iOS\u5e94\u7528\u7a0b\u5e8f\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee3\u7801\u6216Interface Builder\u521b\u5efaUIWebView\u6216WKWebVie<a href=\"https:\/\/appdabao.yimenapp.com\/jiage-299.html\">\u628a\u7f51\u7ad9\u6253\u5305\u5230app<\/a>w\u7ec4\u4ef6\u3002\u4ee5\u4e0b\u662f\u901a\u8fc7\u4ee3\u7801\u521b\u5efaUIWebView\u7684\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<p>&#8220;`<\/p>\n<p>UIWebView *webView = [[UIWebView alloc] initWithFrame:self.view.bounds];<\/p>\n<p>webView.delegate = self;<\/p>\n<p>[self.view addSubview:webView];<\/p>\n<p>&#8220;`<\/p>\n<p>\u4ee5\u4e0b\u662f\u901a\u8fc7Interface Builder\u521b\u5efaUIWebView\u7684\u6b65\u9aa4\uff1a<\/p>\n<p>1.\u6253\u5f00Storyboard\u6216XIB\u6587\u4ef6\uff1b<\/p>\n<p>2.\u62d6\u62fd\u4e00\u4e2aWebView\u63a7\u4ef6\u5230\u89c6\u56fe\u4e2d\uff1b<\/p>\n<p>3.\u8bbe\u7f6eWebView\u63a7\u4ef6\u7684\u5c5e\u6027\uff0c\u5982Frame\u3001BackgroundColor\u3001Delegate\u7b49\u3002<\/p>\n<p>2.\u5c06UIWebView\u6216WKWebView\u7ec4\u4ef6\u6dfb\u52a0\u5230\u5e94\u7528\u7a0b\u5e8f\u7684\u89c6\u56fe\u5c42\u6b21\u7ed3\u6784\u4e2d<\/p>\n<p>\u5c06UIWebView\u6216WKWebView\u7ec4\u4ef6\u6dfb\u52a0\u5230\u5e94\u7528\u7a0b\u5e8f\u7684\u89c6\u56fe\u5c42\u6b21\u7ed3\u6784\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528addSubview\u65b9\u6cd5\u3002\u4ee5\u4e0b\u662f\u5c06UIWebView\u6dfb\u52a0\u5230\u5e94\u7528\u7a0b\u5e8f\u89c6\u56fe\u4e2d\u7684\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<p>&#8220;`<\/p>\n<p>[self.view addSubview:webView];<\/p>\n<p>&#8220;`<\/p>\n<p>3.\u52a0\u8f7dH5\u9875\u9762<\/p>\n<p>\u5c06H5\u9875\u9762\u52a0\u8f7d\u5230UIWebView\u6216WKWebView\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528loadRequest\u65b9\u6cd5\u3002\u4ee5\u4e0b\u662f\u5c06H5\u9875\u9762\u52a0\u8f7d\u5230UIWebView\u4e2d\u7684\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<p>&#8220;`<\/p>\n<p>NSURL *url = [NSURL URLWithString:@&#8221;http:\/\/www.example.com&#8221;];<\/p>\n<p>NSURLRequest *request = [NSURLRequest requestWithURL:url];<\/p>\n<p>[webView loadRequest:request];<\/p>\n<p>&#8220;`<\/p>\n<p>4.\u5728\u5e94\u7528\u7a0b\u5e8f\u4e2d\u5904\u7406H5\u9875\u9762\u7684\u4e8b\u4ef6\u548c\u4ea4\u4e92<\/p>\n<p>\u5728\u5e94\u7528\u7a0b\u5e8f\u4e2d\u5904\u7406H5\u9875\u9762\u7684\u4e8b\u4ef6\u548c\u4ea4\u4e92\uff0c\u53ef\u4ee5\u4f7f\u7528UIWebViewDelegate\u6216WKNavigationDelegate\u534f\u8bae\u3002\u8fd9\u4e9b\u534f\u8bae\u5141\u8bb8\u5e94\u7528\u7a0b\u5e8f\u62e6\u622a\u7f51\u9875\u8bf7\u6c42\u3001\u5904\u7406\u7f51\u9875\u54cd\u5e94\u3001\u5904\u7406\u7528\u6237\u4ea4\u4e92\u7b49\u3002\u4ee5\u4e0b\u662f\u4f7f\u7528UIWebViewDelegate\u5904\u7406\u7f51\u9875\u8bf7\u6c42\u7684\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<p>&#8220;`<\/p>\n<p>&#8211; (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURL<\/p>\n<p><figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/i.cdn.yimenapp.com\/2023-03\/24\/10\/01894135785.jpg\" \/><\/figure>\n<\/p>\n<p>Request *)request navigationType:(UIWebViewNavigationType)navigationType {<\/p>\n<p>    \/\/ \u62e6\u622a\u7f51\u9875\u8bf7\u6c42<\/p>\n<p>    return YES;<\/p>\n<p>}<\/p>\n<p>&#8211; (void)webViewDidStartLoad:(UIWebView *)webView {<\/p>\n<p>    \/\/ \u7f51\u9875\u5f00\u59cb\u52a0\u8f7d<\/p>\n<p>}<\/p>\n<p>&#8211; (void)webViewDidFinishLoad:(UIWebView *)webView {<\/p>\n<p>    \/\/ \u7f51\u9875\u52a0\u8f7d\u5b8c\u6210<\/p>\n<p>}<\/p>\n<p>&#8211; (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {<\/p>\n<p>    \/\/ \u7f51\u9875\u52a0\u8f7d\u5931\u8d25<\/p>\n<p>}<\/p>\n<p>&#8220;`<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fiOS\u5e94\u7528\u7a0b\u5e8f\u4e2d\u5c06H5\u5d4c\u5165\u7684\u539f\u7406\u548c\u8be6\u7ec6\u4ecb\u7ecd\u3002\u901a\u8fc7\u5c06H5\u5d4c\u5165iOS\u5e94\u7528\u7a0b\u5e8f\u4e2d\uff0c\u53ef\u4ee5\u4e3a\u7528\u6237\u63d0\u4f9b\u66f4\u597d\u7684\u4f53\u9a8c\u548c\u4ea4\u4e92\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>iOS\u5e94\u7528\u7a0b\u5e8f\u53ef\u4ee5\u96c6\u6210\u7f51\u9875\u6d4f\u89c8\u5668\uff0c\u4ee5\u4fbf\u76f4\u63a5\u5728\u5e94\u7528\u7a0b\u5e8f\u4e2d\u52a0\u8f7d\u7f51\u9875\u3002\u8fd9\u79cd\u96c6\u6210\u65b9\u5f0f\u88ab\u79f0\u4e3a\u5c06H5\u5d4c\u5165iOS\u5e94\u7528\u7a0b\u5e8f\u4e2d\u3002\u5c06H5\u5d4c\u5165iOS\u5e94\u7528\u7a0b\u5e8f\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u5e94\u7528\u7a0b\u5e8f\u66f4\u52a0\u4e30\u5bcc\u591a\u5f69\uff0c\u589e\u52a0\u7528\u6237\u4f53\u9a8c\u548c\u4ea4\u4e92\u6027\u3002\u4e0b\u9762\u662fiO<\/p>\n","protected":false},"author":12,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[9309,3735,11,20062,206],"topic":[],"class_list":["post-13500","post","type-post","status-publish","format-standard","hentry","category-sjapp","tag-html5","tag-3735","tag-11","tag-ios","tag-206"],"_links":{"self":[{"href":"https:\/\/h5app.yimenapp.cn\/h5app\/wp-json\/wp\/v2\/posts\/13500","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/h5app.yimenapp.cn\/h5app\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/h5app.yimenapp.cn\/h5app\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/h5app.yimenapp.cn\/h5app\/wp-json\/wp\/v2\/users\/12"}],"replies":[{"embeddable":true,"href":"https:\/\/h5app.yimenapp.cn\/h5app\/wp-json\/wp\/v2\/comments?post=13500"}],"version-history":[{"count":1,"href":"https:\/\/h5app.yimenapp.cn\/h5app\/wp-json\/wp\/v2\/posts\/13500\/revisions"}],"predecessor-version":[{"id":13665,"href":"https:\/\/h5app.yimenapp.cn\/h5app\/wp-json\/wp\/v2\/posts\/13500\/revisions\/13665"}],"wp:attachment":[{"href":"https:\/\/h5app.yimenapp.cn\/h5app\/wp-json\/wp\/v2\/media?parent=13500"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/h5app.yimenapp.cn\/h5app\/wp-json\/wp\/v2\/categories?post=13500"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/h5app.yimenapp.cn\/h5app\/wp-json\/wp\/v2\/tags?post=13500"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/h5app.yimenapp.cn\/h5app\/wp-json\/wp\/v2\/topic?post=13500"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}