{"id":2087,"date":"2024-11-10T09:09:29","date_gmt":"2024-11-10T01:09:29","guid":{"rendered":"https:\/\/fwq.ai\/blog\/2087\/"},"modified":"2024-11-10T09:09:29","modified_gmt":"2024-11-10T01:09:29","slug":"javascript-%e5%a6%82%e4%bd%95%e5%9c%a8%e6%89%8b%e6%9c%ba%e4%b8%8a%e5%88%a4%e6%96%ad%e7%89%b9%e5%ae%9a%e5%ba%94%e7%94%a8%e6%98%af%e5%90%a6%e5%b7%b2%e5%ae%89%e8%a3%85%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/2087\/","title":{"rendered":"JavaScript \u5982\u4f55\u5728\u624b\u673a\u4e0a\u5224\u65ad\u7279\u5b9a\u5e94\u7528\u662f\u5426\u5df2\u5b89\u88c5\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173063918936804.jpg\" class=\"aligncenter\" title=\"JavaScript \u5982\u4f55\u5728\u624b\u673a\u4e0a\u5224\u65ad\u7279\u5b9a\u5e94\u7528\u662f\u5426\u5df2\u5b89\u88c5\uff1f\u63d2\u56fe\" alt=\"JavaScript \u5982\u4f55\u5728\u624b\u673a\u4e0a\u5224\u65ad\u7279\u5b9a\u5e94\u7528\u662f\u5426\u5df2\u5b89\u88c5\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u5728 javascript \u4e2d\u5224\u65ad\u624b\u673a\u4e0a\u662f\u5426\u5b89\u88c5\u4e86\u7279\u5b9a\u5e94\u7528<\/strong><\/p>\n<p>\u5728\u5f00\u53d1\u4e2d\uff0c\u6709\u65f6\u9700\u8981\u68c0\u6d4b\u624b\u673a\u4e0a\u662f\u5426\u5b89\u88c5\u4e86\u7279\u5b9a\u7684\u5e94\u7528\u7a0b\u5e8f\u3002\u4f8b\u5982\uff0c\u60a8\u53ef\u80fd\u5e0c\u671b\u5728\u767b\u5f55\u9875\u9762\u4e0a\u663e\u793a\u7279\u5b9a\u793e\u4ea4\u5a92\u4f53\u5e73\u53f0\u7684\u5feb\u6377\u767b\u5f55\u6309\u94ae\uff0c\u4f46\u524d\u63d0\u662f\u7528\u6237\u5df2\u7ecf\u5b89\u88c5\u4e86\u8be5\u5e94\u7528\u7a0b\u5e8f\u3002\u4f20\u7edf\u7684\u68c0\u6d4b\u65b9\u6cd5\u6d89\u53ca\u5c1d\u8bd5\u6253\u5f00\u8be5\u5e94\u7528\u7a0b\u5e8f\uff0c\u5982\u679c\u6210\u529f\u5219\u8868\u660e\u5df2\u5b89\u88c5\u3002\u7136\u800c\uff0c\u5f00\u53d1\u4eba\u5458\u901a\u5e38\u5e0c\u671b\u4ec5\u8fdb\u884c\u68c0\u6d4b\uff0c\u800c\u65e0\u9700\u5b9e\u9645\u542f\u52a8\u5e94\u7528\u7a0b\u5e8f\u3002<\/p>\n<p>\u4e00\u4e2a\u53ef\u884c\u7684\u89e3\u51b3\u65b9\u6848\u662f\u5229\u7528\u7b2c\u4e09\u65b9\u63d2\u4ef6\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u7528\u63d2\u4ef6\u7684\u793a\u4f8b\uff1a<\/p>\n<ul>\n<li> <strong>appavlability<\/strong>\uff1a\u5b83\u662f\u4e00\u4e2a\u7528\u4e8e android \u548c ios \u7684\u8de8\u5e73\u53f0\u63d2\u4ef6\uff0c\u63d0\u4f9b isappavailable(appid) \u65b9\u6cd5\u6765\u68c0\u6d4b\u662f\u5426\u5b89\u88c5\u4e86\u5e94\u7528\u7a0b\u5e8f\u3002<\/li>\n<li> <strong>appurl<\/strong>\uff1a\u9002\u7528\u4e8e ios \u7684\u63d2\u4ef6\uff0c\u5b83\u5177\u6709 canopenurl(url) \u65b9\u6cd5\uff0c\u53ef\u7528\u4e8e\u68c0\u67e5\u7279\u5b9a\u5e94\u7528\u7a0b\u5e8f\u7684 url \u662f\u5426\u53ef\u4ee5\u6253\u5f00\u3002<\/li>\n<li> <strong>cordova-plugin-appmanager<\/strong>\uff1a\u8fd9\u662f\u4e00\u4e2a\u9488\u5bf9 cordova \u5e94\u7528\u7a0b\u5e8f\u7684\u63d2\u4ef6\uff0c\u5b83\u63d0\u4f9b\u4e86 getappid(path) \u65b9\u6cd5\u6765\u83b7\u53d6\u5b89\u88c5\u7684\u5e94\u7528\u7a0b\u5e8f\u7684 id\uff0c\u4ece\u800c\u53ef\u4ee5\u5bf9\u5176\u8fdb\u884c\u68c0\u6d4b\u3002<\/li>\n<\/ul>\n<p><strong>\u4f7f\u7528\u793a\u4f8b<\/strong><\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<p>\u4ee5\u4e0b\u5c55\u793a\u4e86\u5982\u4f55\u4f7f\u7528 appavailability \u63d2\u4ef6\u68c0\u6d4b\u662f\u5426\u5b89\u88c5\u4e86 whatsapp\uff1a<\/p>\n<pre>import { isAppAvailable } from \"cordova-plugin-app-availability\";\n\nasync function checkWhatsApp() {\n  const isInstalled = await isAppAvailable({ appId: \"com.whatsapp\" });\n  if (isInstalled) {\n    \/\/ \u663e\u793a WhatsApp \u5feb\u6377\u767b\u5f55\u6309\u94ae\n  } else {\n    \/\/ \u9690\u85cf WhatsApp \u5feb\u6377\u767b\u5f55\u6309\u94ae\n  }\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u901a\u8fc7\u4f7f\u7528\u8fd9\u4e9b\u63d2\u4ef6\uff0c\u60a8\u53ef\u4ee5\u8f7b\u677e\u68c0\u6d4b\u624b\u673a\u4e0a\u662f\u5426\u5b89\u88c5\u4e86\u7279\u5b9a\u7684\u5e94\u7528\u7a0b\u5e8f\uff0c\u4ece\u800c\u66f4\u7075\u6d3b\u5730\u5b9a\u5236\u60a8\u7684\u5e94\u7528\u7a0b\u5e8f\u884c\u4e3a\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fJavaScript \u5982\u4f55\u5728\u624b\u673a\u4e0a\u5224\u65ad\u7279\u5b9a\u5e94\u7528\u662f\u5426\u5df2\u5b89\u88c5\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u4f55\u5728 javascript \u4e2d\u5224\u65ad\u624b\u673a\u4e0a\u662f\u5426\u5b89\u88c5\u4e86\u7279\u5b9a\u5e94\u7528 \u5728\u5f00\u53d1\u4e2d\uff0c\u6709\u65f6\u9700\u8981\u68c0\u6d4b\u624b\u673a\u4e0a\u662f\u5426\u5b89\u88c5\u4e86\u7279\u5b9a\u7684\u5e94\u7528\u7a0b\u5e8f\u3002\u4f8b\u5982\uff0c\u60a8\u53ef\u80fd\u5e0c\u671b\u5728\u767b\u5f55\u9875\u9762\u4e0a\u663e\u793a\u7279\u5b9a\u793e\u4ea4\u5a92\u4f53\u5e73\u53f0\u7684\u5feb\u6377\u767b\u5f55\u6309\u94ae\uff0c\u4f46\u524d\u63d0\u662f\u7528\u6237\u5df2\u7ecf\u5b89\u88c5\u4e86\u8be5\u5e94\u7528\u7a0b\u5e8f\u3002\u4f20\u7edf\u7684\u68c0\u6d4b\u65b9\u6cd5\u6d89\u53ca\u5c1d\u8bd5\u6253\u5f00\u8be5\u5e94\u7528\u7a0b\u5e8f\uff0c\u5982\u679c\u6210\u529f\u5219\u8868\u660e\u5df2\u5b89\u88c5\u3002\u7136\u800c\uff0c\u5f00\u53d1\u4eba\u5458\u901a\u5e38\u5e0c\u671b\u4ec5\u8fdb\u884c\u68c0\u6d4b\uff0c\u800c\u65e0\u9700\u5b9e\u9645\u542f\u52a8\u5e94\u7528\u7a0b\u5e8f\u3002 \u4e00\u4e2a\u53ef\u884c\u7684\u89e3\u51b3\u65b9\u6848\u662f\u5229\u7528\u7b2c\u4e09\u65b9\u63d2\u4ef6\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u7528\u63d2\u4ef6\u7684\u793a\u4f8b\uff1a appavlability\uff1a\u5b83\u662f\u4e00\u4e2a\u7528\u4e8e android \u548c ios \u7684\u8de8\u5e73\u53f0\u63d2\u4ef6\uff0c\u63d0\u4f9b isappavailable(appid) \u65b9\u6cd5\u6765\u68c0\u6d4b\u662f\u5426\u5b89\u88c5\u4e86\u5e94\u7528\u7a0b\u5e8f\u3002 appurl\uff1a\u9002\u7528\u4e8e ios \u7684\u63d2\u4ef6\uff0c\u5b83\u5177\u6709 canopenurl(url) \u65b9\u6cd5\uff0c\u53ef\u7528\u4e8e\u68c0\u67e5\u7279\u5b9a\u5e94\u7528\u7a0b\u5e8f\u7684 url \u662f\u5426\u53ef\u4ee5\u6253\u5f00\u3002 cordova-plugin-appmanager\uff1a\u8fd9\u662f\u4e00\u4e2a\u9488\u5bf9 cordova \u5e94\u7528\u7a0b\u5e8f\u7684\u63d2\u4ef6\uff0c\u5b83\u63d0\u4f9b\u4e86 getappid(path) \u65b9\u6cd5\u6765\u83b7\u53d6\u5b89\u88c5\u7684\u5e94\u7528\u7a0b\u5e8f\u7684 id\uff0c\u4ece\u800c\u53ef\u4ee5\u5bf9\u5176\u8fdb\u884c\u68c0\u6d4b\u3002 \u4f7f\u7528\u793a\u4f8b \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b \u4ee5\u4e0b\u5c55\u793a\u4e86\u5982\u4f55\u4f7f\u7528 appavailability \u63d2\u4ef6\u68c0\u6d4b\u662f\u5426\u5b89\u88c5\u4e86 whatsapp\uff1a import { isAppAvailable } from &#8220;cordova-plugin-app-availability&#8221;; async function checkWhatsApp() { const isInstalled = await isAppAvailable({ appId: &#8220;com.whatsapp&#8221; }); if (isInstalled) { \/\/ \u663e\u793a WhatsApp [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-2087","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/2087","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=2087"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/2087\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=2087"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=2087"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=2087"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}