{"id":186414,"date":"2023-07-28T07:13:58","date_gmt":"2023-07-27T23:13:58","guid":{"rendered":"http:\/\/www.idc.net\/help\/186414\/"},"modified":"2023-07-28T07:13:58","modified_gmt":"2023-07-27T23:13:58","slug":"%e5%90%8e%e6%b5%aa%e4%ba%91%e7%99%be%e5%ba%a6%e5%b0%8f%e7%a8%8b%e5%ba%8f%e6%95%99%e7%a8%8b%ef%bc%9aswan-getnetworktype","status":"publish","type":"post","link":"https:\/\/idc.net\/help\/186414\/","title":{"rendered":"\u540e\u6d6a\u4e91\u767e\u5ea6\u5c0f\u7a0b\u5e8f\u6559\u7a0b\uff1aswan.getNetworkType"},"content":{"rendered":"<ul>\n<li>swan.getNetworkType\n<ul>\n<li>\u65b9\u6cd5\u53c2\u6570\n<ul>\n<li>object \u53c2\u6570\u8bf4\u660e<\/li>\n<\/ul>\n<\/li>\n<li>\u793a\u4f8b\n<ul>\n<li>\u56fe\u7247\u793a\u4f8b<\/li>\n<li>\u4ee3\u7801\u793a\u4f8b<\/li>\n<\/ul>\n<\/li>\n<li>\u9519\u8bef\u7801\n<ul>\n<li>Android\n<ul><\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h1><span><\/span>swan.getNetworkType<\/h1>\n<p><strong>\u89e3\u91ca<\/strong>\uff1a\u83b7\u53d6\u7f51\u7edc\u7c7b\u578b<\/p>\n<h2><span><\/span>\u65b9\u6cd5\u53c2\u6570<\/h2>\n<p>Object object<\/p>\n<h3><span><\/span>object \u53c2\u6570\u8bf4\u660e<\/h3>\n<table>\n<thead>\n<tr>\n<th>\u5c5e\u6027\u540d<\/th>\n<th>\u7c7b\u578b<\/th>\n<th>\u5fc5\u586b<\/th>\n<th>\u9ed8\u8ba4\u503c<\/th>\n<th>\u8bf4\u660e<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>\n<p>success<\/p>\n<\/td>\n<td>\n<p>Function<\/p>\n<\/td>\n<td>\n<p>\u5426<\/p>\n<\/td>\n<td><\/td>\n<td>\n<p>\u63a5\u53e3\u8c03\u7528\u6210\u529f\uff0c\u8fd4\u56de\u7f51\u7edc\u7c7b\u578b networkType<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>fail<\/p>\n<\/td>\n<td>\n<p>Function<\/p>\n<\/td>\n<td>\n<p>\u5426<\/p>\n<\/td>\n<td><\/td>\n<td>\n<p>\u63a5\u53e3\u8c03\u7528\u5931\u8d25\u7684\u56de\u8c03\u51fd\u6570<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>complete<\/p>\n<\/td>\n<td>\n<p>Function<\/p>\n<\/td>\n<td>\n<p>\u5426<\/p>\n<\/td>\n<td><\/td>\n<td>\n<p>\u63a5\u53e3\u8c03\u7528\u7ed3\u675f\u7684\u56de\u8c03\u51fd\u6570\uff08\u8c03\u7528\u6210\u529f\u3001\u5931\u8d25\u90fd\u4f1a\u6267\u884c\uff09<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>success \u8fd4\u56de\u53c2\u6570\u8bf4\u660e \uff1a<\/p>\n<table>\n<thead>\n<tr>\n<th>\u53c2\u6570<\/th>\n<th>\u7c7b\u578b<\/th>\n<th>\u8bf4\u660e<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>\n<p>networkType<\/p>\n<\/td>\n<td>\n<p>String<\/p>\n<\/td>\n<td>\n<p>\u7f51\u7edc\u7c7b\u578b<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>networkType \u6709\u6548\u503c\u8bf4\u660e \uff1a<\/p>\n<table>\n<thead>\n<tr>\n<th>\u503c<\/th>\n<th>\u8bf4\u660e<\/th>\n<th>Web \u6001\u8bf4\u660e<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>\n<p>wifi<\/p>\n<\/td>\n<td>\n<p>wifi \u7f51\u7edc<\/p>\n<\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td>\n<p>2g<\/p>\n<\/td>\n<td>\n<p>2g \u7f51\u7edc<\/p>\n<\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td>\n<p>3g<\/p>\n<\/td>\n<td>\n<p>3g \u7f51\u7edc<\/p>\n<\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td>\n<p>4g<\/p>\n<\/td>\n<td>\n<p>4g \u7f51\u7edc<\/p>\n<\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td>\n<p>unknown<\/p>\n<\/td>\n<td>\n<p>Android \u548c Web \u6001\u4e0b\u4e0d\u5e38\u89c1\u7684\u7f51\u7edc\u7c7b\u578b<\/p>\n<\/td>\n<td>\n<p>\u7531\u4e8e\u6d4f\u89c8\u5668\u5bf9\u4e8e W3C \u89c4\u8303\u7684\u5b9e\u73b0\u5dee\u5f02\uff0c\u5728 Web \u6001\u4e2d\u53ef\u80fd\u8fd4\u56de unknown\uff08\u5982 iOS Web \u6001\uff09\uff0c\u5e76\u975e\u4ee3\u8868\u7f51\u7edc\u5f02\u5e38\uff0c\u8bf7\u52ff\u5728\u8fd4\u56de\u503c\u4e3a unknown \u65f6\u5f53\u4f5c\u7f51\u7edc\u5f02\u5e38\u5904\u7406\u3002\u5efa\u8bae\u63d0\u793a\u7528\u6237\u786e\u8ba4\u7f51\u7edc\u72b6\u6001\u540e\u6309\u6b63\u5e38\u7f51\u7edc\u60c5\u51b5\u5904\u7406<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>none<\/p>\n<\/td>\n<td>\n<p>\u65e0\u7f51\u7edc<\/p>\n<\/td>\n<td><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2><span><\/span>\u793a\u4f8b<\/h2>\n<p>\u8df3\u8f6c\u7f16\u8f91\u5de5\u5177<\/p>\n<p>\u5728\u5f00\u53d1\u8005\u5de5\u5177\u4e2d\u6253\u5f00<\/p>\n<p>\u5728 WEB IDE \u4e2d\u6253\u5f00<\/p>\n<p>\u626b\u7801\u4f53\u9a8c<\/p>\n<p>\u4ee3\u7801\u793a\u4f8b<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/static.sitestack.cn\/projects\/smartprogram-20210306\/97ebf63311ffac886baad1c970c1b97b.png\" class=\"aligncenter\"><\/p>\n<p>\u8bf7\u4f7f\u7528\u767e\u5ea6APP\u626b\u7801<\/p>\n<h3><span><\/span>\u56fe\u7247\u793a\u4f8b<\/h3>\n<p><img decoding=\"async\" src=\"https:\/\/static.sitestack.cn\/projects\/smartprogram-20210306\/3f4490a5fb8e33f24080d09b81c26b1d.gif\" class=\"aligncenter\"><\/p>\n<\/p>\n<h3><span><\/span>\u4ee3\u7801\u793a\u4f8b<\/h3>\n<ul>\n<li>SWAN<\/li>\n<li>JS<\/li>\n<\/ul>\n<pre>\n \n \n <ol>\n  \n  \n  <li><code><span>&lt;view<\/span><span> <\/span><span>class<\/span><span>=<\/span><span>\"wrap\"<\/span><span>&gt;<\/span><\/code><\/li>\n  \n  \n  <li><code><span> <\/span><span>&lt;view<\/span><span> <\/span><span>class<\/span><span>=<\/span><span>\"card-area\"<\/span><span>&gt;<\/span><\/code><\/li>\n  \n  \n  <li><code><span> <\/span><span>&lt;view<\/span><span> <\/span><span>class<\/span><span>=<\/span><span>\"display-area\"<\/span><span>&gt;<\/span><\/code><\/li>\n  \n  \n  <li><code><span> <\/span><span>&lt;view<\/span><span> <\/span><span>class<\/span><span>=<\/span><span>\"tip-week\"<\/span><span>&gt;<\/span><span>\u5f53\u524d\u7f51\u7edc\u7c7b\u578b<\/span><span>&lt;\/view&gt;<\/span><\/code><\/li>\n  \n  \n  <li><code><span> <\/span><span>&lt;view<\/span><span> <\/span><span>class<\/span><span>=<\/span><span>\"result-area-default\"<\/span><span> <\/span><span>s-if<\/span><span>=<\/span><span>\"{{changeData}}\"<\/span><span>&gt;<\/span><span>\u672a\u83b7\u53d6<\/span><span>&lt;\/view&gt;<\/span><\/code><\/li>\n  \n  \n  <li><code><span> <\/span><span>&lt;view<\/span><span> <\/span><span>s-else<\/span><span> <\/span><span>class<\/span><span>=<\/span><span>\"workType ? result-area-succ : result-area-fail\"<\/span><span>&gt;<\/span><span>{{networkType}}<\/span><span>&lt;\/view&gt;<\/span><\/code><\/li>\n  \n  \n  <li><code><span> <\/span><span>&lt;\/view&gt;<\/span><\/code><\/li>\n  \n  \n  <li><code><span> <\/span><span>&lt;button<\/span><span> <\/span><span>class<\/span><span>=<\/span><span>\"btn\"<\/span><span> <\/span><span>bind:tap<\/span><span>=<\/span><span>\"getNetworkType\"<\/span><span> <\/span><span>type<\/span><span>=<\/span><span>\"primary\"<\/span><span> <\/span><span>hover-stop-propagation<\/span><span>=<\/span><span>\"true\"<\/span><span>&gt;<\/span><span>\u70b9\u51fb\u83b7\u53d6\u7f51\u7edc\u7c7b\u578b<\/span><span>&lt;\/button&gt;<\/span><\/code><\/li>\n  \n  \n  <li><code><span> <\/span><span>&lt;\/view&gt;<\/span><\/code><\/li>\n  \n  \n  <li><code><span>&lt;\/view&gt;<\/span><\/code><\/li>\n \n \n <\/ol><\/pre>\n<h2><span><\/span>\u9519\u8bef\u7801<\/h2>\n<h3><span><\/span>Android<\/h3>\n<table>\n<thead>\n<tr>\n<th>\u9519\u8bef\u7801<\/th>\n<th>\u8bf4\u660e<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>\n<p>202<\/p>\n<\/td>\n<td>\n<p>\u89e3\u6790\u5931\u8d25\uff0c\u8bf7\u68c0\u67e5\u53c2\u6570\u662f\u5426\u6b63\u786e<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n","protected":false},"excerpt":{"rendered":"<p>swan.getNetworkType \u65b9\u6cd5\u53c2\u6570 object \u53c2\u6570\u8bf4\u660e \u793a\u4f8b \u56fe\u7247\u793a\u4f8b \u4ee3\u7801\u793a\u4f8b \u9519\u8bef\u7801 A [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":186415,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[182398],"tags":[],"class_list":["post-186414","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-mini-program"],"_links":{"self":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts\/186414","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/comments?post=186414"}],"version-history":[{"count":0,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts\/186414\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/media\/186415"}],"wp:attachment":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/media?parent=186414"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/categories?post=186414"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/tags?post=186414"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}