{"id":28946,"date":"2024-04-01T18:27:23","date_gmt":"2024-04-01T10:27:23","guid":{"rendered":"https:\/\/app.60day.cn\/appday\/?p=28946"},"modified":"2024-04-01T18:27:23","modified_gmt":"2024-04-01T10:27:23","slug":"%e7%bd%91%e9%a1%b5app%e7%94%9f%e6%88%90%e6%ba%90%e7%a0%81%e4%bd%9c%e7%94%a8%e4%bb%8b%e7%bb%8d","status":"publish","type":"post","link":"https:\/\/app.60day.cn\/appday\/kaifaapp\/28946\/","title":{"rendered":"\u7f51\u9875app\u751f\u6210\u6e90\u7801\u4f5c\u7528\u4ecb\u7ecd"},"content":{"rendered":"<p><figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/i.cdn.yimenapp.com\/2023-01\/06\/14\/20513523182.jpg\" \/><\/figure>\n<\/p>\n<p>\u7f51\u9875App\u751f\u6210\u6e90\u7801\u662f\u5c06\u73b0\u6709\u7f51\u7ad9\u5e94\u7528\u8f6c\u6362\u6210\u672c\u5730App\u5e94\u7528\u7684\u8fc7\u7a0b\u3002\u8fd9\u79cd\u5e94\u7528\u4e5f\u79f0\u4e3a&#8221;Webview\u5e94\u7528&#8221;\uff0c\u5176\u4e3b\u8981\u539f\u7406\u662f\u5229\u7528\u79fb\u52a8\u8bbe\u5907\uff08\u5b89\u5353\u6216iOS\uff09\u7684\u5185\u7f6eWebview\u7ec4\u4ef6\u76f4\u63a5\u6e32\u67d3\u7f51\u9875\uff0c\u4e3a\u7528\u6237\u63d0\u4f9b\u7c7b\u4f3c\u4e8e\u539f\u751fApp\u7684\u4f7f\u7528\u4f53\u9a8c\u3002\u73b0\u5728\u6211\u4eec\u5c06\u8be6\u7ec6\u4ecb\u7ecdWebview\u5e94\u7528\u7684\u751f\u6210\u6e90\u7801\u8fc7\u7a0b\u3002<\/p>\n<p>\u9996\u5148\u6211\u4eec\u9700\u8981\u4e86\u89e3\u5b89\u5353\u548ciOS\u5e73\u53f0\u7684\u57fa\u672c\u67b6\u6784\uff0c\u5b89\u5353\u4f7f\u7528Java\/Kotlin\u4f5c\u4e3a\u4e3b\u8981\u5f00\u53d1\u8bed\u8a00\uff0c\u800ciOS\u4f7f\u7528Swift\/Objective-C\u4f5c\u4e3a\u4e3b\u8981\u5f00\u53d1\u8bed\u8a00\u3002\u8fd9\u4e24\u4e2a\u5e73\u53f0\u90fd\u63d0\u4f9b\u4e86\u5185\u7f6e\u7684WebView\u7ec4\u4ef6\uff0c\u7528\u4e8e\u6e32\u67d3\u7f51\u9875\u3002<\/p>\n<p>**\u5b89\u5353\u5e73\u53f0\uff08Java\uff09:**<\/p>\n<p>1. \u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u5b89\u5353\u9879\u76ee\u3002<\/p>\n<p>2. \u5728`activity_main.xml`\u5e03\u5c40\u6587\u4ef6\u4e2d\uff0c\u5f15\u5165WebView\u7ec4\u4ef6\u5e76\u4e3a\u5176\u5206\u914d\u4e00\u4e2aID\u3002<\/p>\n<p>&#8220;`xml<\/p>\n<\/p>\n<p>    android:id=&#8221;@+id\/webview&#8221;<\/p>\n<p>    android:layout_width=&#8221;match_parent&#8221;<\/p>\n<p>    android:layout_height=&#8221;match_parent&#8221; \/&gt;<\/p>\n<p>&#8220;`<\/p>\n<p>3. \u5728`MainActivity.java`\u6587\u4ef6\u4e2d\uff0c\u521d\u59cb\u5316WebView\u7ec4\u4ef6\uff0c\u5e76\u8bbe\u7f6eWebView\u7684\u5c5e\u6027\u548cURI\u5730\u5740\u3002<\/p>\n<p>&#8220;`java<\/p>\n<p>import android.webkit.WebSettings;<\/p>\n<p>import android.webkit.WebView;<\/p>\n<p>import android.webkit.WebViewClient;<\/p>\n<p>public class MainActivity extends AppCompatActivity {<\/p>\n<p>    private WebView webView;<\/p>\n<p>    @Override<\/p>\n<p>    protected void onCreate(Bundle savedInstanceState) {<\/p>\n<p>        super.onCreate(savedInstanceState);<\/p>\n<p>        setContentView(R.layout.activity_main);<\/p>\n<p>        webView = findViewById(R.id.webview);<\/p>\n<p>        WebSettings webSettings = webView.getSettings();<\/p>\n<p>        webSettings.setJavaScriptEnabled(true);<\/p>\n<p>        webView.setWebViewClient(new WebViewClient());<\/p>\n<p>        webView.loadUrl(&#8220;https:\/\/example.com&#8221;);<\/p>\n<p>    }<\/p>\n<p>    @Override<\/p>\n<p>    public void onBackPressed() {<\/p>\n<p>        if (webView.canGoBack()) {<\/p>\n<p>            webView.goBack();<\/p>\n<p>        } else {<\/p>\n<p>            super.onBackPressed();<\/p>\n<p>        }<\/p>\n<p>    }<\/p>\n<p>}<\/p>\n<p>&#8220;`<\/p>\n<p>**iOS\u5e73\u53f0\uff08Swift\uff09:**<\/p>\n<p>1. \u521b\u5efa\u65b0\u7684iOS\u9879\u76ee\u3002<\/p>\n<p>2. \u5728`ViewController.swift`\u6587\u4ef6\u4e2d\u5bfc\u5165`WebKit`\u6846\u67b6\uff0c\u5e76\u521b\u5efa\u4e00\u4e2a`WKWebView`\u5bf9\u8c61\u3002<\/p>\n<p>&#8220;`swift<\/p>\n<p>import UIKit<\/p>\n<p>import WebKit<\/p>\n<p>class ViewController: UIViewController, WKUIDelegate {<\/p>\n<\/p>\n<p>  var webView: WKWebView!<\/p>\n<p>  override func viewDidLoad() {<\/p>\n<p>    super.viewDidLoad()<\/p>\n<p>    let webConfiguration = WKWebViewConfiguration()<\/p>\n<p>    webView = WKWebView(frame: .zero, configuration: webConfiguration)<\/p>\n<p>    webView.uiDelegate = self<\/p>\n<p>    view = webView<\/p>\n<p>    let myURL = URL(string: &#8220;https:\/\/example.com&#8221;)<\/p>\n<p>    let myRequest = URLRequest(url: myURL!)<\/p>\n<p>    webView.load(myRequest)<\/p>\n<p>  }<\/p>\n<p>}<\/p>\n<p>&#8220;<a href=\"http:\/\/www.yimenyun.cn\/app-shengcheng-gongju-151.html\">\u7f51\u7ad9\u5728\u7ebf\u81ea\u52a8\u751f\u6210app<\/a>`<\/p>\n<p>3. \u5728`info.plist`\u6587\u4ef6\u4e2d\uff0c\u6253\u5f00\u4e0d\u5b89\u5168\u57df\u7684\u52a0\u8f7d\u914d\u7f6e\u3002\uff08\u4ec5\u7528\u4e8e\u5f00\u53d1\u8fc7\u7a0b\u4e2d\uff0c\u8bf7\u52ff\u5728\u751f\u4ea7\u73af\u5883\u4f7f\u7528\uff09<\/p>\n<p>&#8220;`<\/p>\n<p>NSAppTransportSecurity<\/p>\n<p>\n<p>\tNSAllowsArbitraryLoads<\/p>\n<\/p>\n<p>&#8220;`<\/p>\n<p>\u81f3\u6b64\uff0c\u6211\u4eec\u5df2\u7ecf\u5b8c\u6210\u4e86\u57fa\u672c\u7684WebView\u5e94\u7528\u3002\u5f53\u7136\uff0c\u4e3a\u4e86\u8ba9WebView\u5e94\u7528\u7684\u529f\u80fd\u66f4\u52a0\u5b8c\u5584\uff0c\u8fd8\u53ef\u4ee5\u6dfb\u52a0\u8bf8\u5982\u6743\u9650\u63a7\u5236\u3001\u6587\u4ef6\u4e0a\u4f20\u4e0b\u8f7d\u3001\u5b9a\u4f4d\u4ee5\u53ca\u4e0e\u539f\u751f\u4ee3\u7801\u7684\u4ea4\u4e92\u7b49\u529f\u80fd\u3002<\/p>\n<p>\u7136\u540e\uff0c\u6211\u4eec\u53ef\u4ee5\u5728\u5bf9\u5e94\u5e73\u53f0\u7684App Store\u6216\u8005Google Play \u5546\u5e97\u4e0a\u53d1\u5e03\u6211\u4eec\u7684\u5e94\u7528\uff0c<a href=\"http:\/\/www.yimenyun.cn\/app-shengcheng-gongju-464.html\">\u7f51\u7ad9\u4e00\u952e\u751f\u6210\u6c38\u4e45\u4ee3\u5237app<\/a>\u4ece\u800c\u8ba9\u66f4\u591a\u7528\u6237\u80fd\u591f\u4e0b\u8f7d\u5b89\u88c5\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u7f51\u9875App\u751f\u6210\u6e90\u7801\u662f\u5c06\u73b0\u6709\u7f51\u7ad9\u5e94\u7528\u8f6c\u6362\u6210\u672c\u5730App\u5e94\u7528\u7684\u8fc7\u7a0b\u3002\u8fd9\u79cd\u5e94\u7528\u4e5f\u79f0\u4e3a\\&#8221;Webview\u5e94\u7528\\&#8221;\uff0c\u5176\u4e3b\u8981\u539f\u7406\u662f\u5229\u7528\u79fb\u52a8\u8bbe\u5907\uff08\u5b89\u5353\u6216iOS\uff09\u7684\u5185\u7f6eWebview\u7ec4\u4ef6\u76f4\u63a5\u6e32\u67d3\u7f51\u9875\uff0c\u4e3a\u7528\u6237\u63d0\u4f9b\u7c7b\u4f3c\u4e8e\u539f\u751f<\/p>\n","protected":false},"author":12,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[12518,304,132,1291,11183],"topic":[],"class_list":["post-28946","post","type-post","status-publish","format-standard","hentry","category-kaifaapp","tag-html5app","tag-304","tag-132","tag-1291","tag-app"],"_links":{"self":[{"href":"https:\/\/app.60day.cn\/appday\/wp-json\/wp\/v2\/posts\/28946","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/app.60day.cn\/appday\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/app.60day.cn\/appday\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/app.60day.cn\/appday\/wp-json\/wp\/v2\/users\/12"}],"replies":[{"embeddable":true,"href":"https:\/\/app.60day.cn\/appday\/wp-json\/wp\/v2\/comments?post=28946"}],"version-history":[{"count":1,"href":"https:\/\/app.60day.cn\/appday\/wp-json\/wp\/v2\/posts\/28946\/revisions"}],"predecessor-version":[{"id":28991,"href":"https:\/\/app.60day.cn\/appday\/wp-json\/wp\/v2\/posts\/28946\/revisions\/28991"}],"wp:attachment":[{"href":"https:\/\/app.60day.cn\/appday\/wp-json\/wp\/v2\/media?parent=28946"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/app.60day.cn\/appday\/wp-json\/wp\/v2\/categories?post=28946"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/app.60day.cn\/appday\/wp-json\/wp\/v2\/tags?post=28946"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/app.60day.cn\/appday\/wp-json\/wp\/v2\/topic?post=28946"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}