{"id":104,"date":"2021-09-07T17:57:47","date_gmt":"2021-09-07T09:57:47","guid":{"rendered":"https:\/\/www.osvlabs.com\/blog\/?p=104"},"modified":"2021-09-12T20:53:11","modified_gmt":"2021-09-12T12:53:11","slug":"cordova%e9%9b%86%e6%88%90firebase%e6%8f%92%e4%bb%b6%e5%ae%9e%e7%8e%b0%e6%b6%88%e6%81%af%e6%8e%a8%e9%80%81","status":"publish","type":"post","link":"https:\/\/blog.osvlabs.com\/?p=104","title":{"rendered":"Cordova\u96c6\u6210firebase\u63d2\u4ef6\u5b9e\u73b0\u6d88\u606f\u63a8\u9001"},"content":{"rendered":"<p>Firebase Cloud Messaging (FCM) \u662f\u4e00\u79cd\u8de8\u5e73\u53f0(\u5b89\u5353\uff0cIOS\uff0cWeb)\u6d88\u606f\u4f20\u9012\u89e3\u51b3\u65b9\u6848\uff0c\u4e14\u65e0\u9700\u4efb\u4f55\u8d39\u7528\u3002<\/p>\n<p>\u6700\u8fd1\u7528cordova\u5f00\u53d1app\uff0c\u5ba2\u6237\u5e0c\u671b\u52a0\u5165\u6d88\u606f\u63a8\u9001\u529f\u80fd\uff0c\u56fd\u5185\u6211\u4eec\u77e5\u9053\u6709\u6fc0\u5149\u63a8\u9001\uff0c\u800c\u56fd\u5916firebase\u975e\u5e38\u51fa\u540d\u3002<\/p>\n<p>\u4f46\u662fcordova\u4f7f\u7528firebase\u9700\u8981\u6ce8\u610f\u4ee5\u4e0b\u51e0\u70b9\uff1a<\/p>\n<ul>\n<li>\n<p>\u56e0\u4e3afirebase\u5df2\u88abgoogle\u6536\u8d2d\uff0c\u56fd\u5185\u624b\u673a\u8bbe\u5907\u65e0\u6cd5\u63a5\u6536\u6765\u81eafirebase\u7684\u63a8\u9001\uff0c\u9664\u975e\u5f00\u4ee3\u7406\uff0c\u8981\u6253\u5f00\u7684\u7aef\u53e3\u548c\u4e3b\u673a\u540d\u89c1<a href=\"https:\/\/firebase.google.com\/docs\/cloud-messaging\/concept-options#messaging-ports-and-your-firewall\">\u5b98\u65b9\u6587\u6863<\/a><\/p>\n<\/li>\n<li>\n<p>\u624b\u673a\u4e0a\u7684app\u8fd0\u884c\u72b6\u6001\u5206\u524d\u53f0\u548c\u540e\u53f0<\/p>\n<ul>\n<li>\u524d\u53f0\u8fd0\u884c\u65f6\u53ef\u4ee5\u63a5\u6536\u5230\u6d88\u606f\u63a8\u9001\uff0c\u4f46\u662f\u4e0d\u4f1a\u6709\u6d88\u606f\u680f\u7684\u63d0\u9192(\u8fd9\u662f\u624b\u673a\u7684\u9ed8\u8ba4\u884c\u4e3a)\uff0c\u5bf9\u4e8e\u5b89\u5353\uff0c\u5982\u679c\u8981\u5728\u524d\u53f0\u663e\u793a\u63a8\u9001\uff0c\u63a8\u8350\u4f7f\u7528<a href=\"https:\/\/github.com\/katzer\/cordova-plugin-local-notifications#readme\">cordova-plugin-local-notification<\/a> \u63d2\u4ef6<\/li>\n<li>\u540e\u53f0\u8fd0\u884c\u6216\u5173\u95ed\u65f6\uff0c\u624b\u673a\u6536\u5230\u63a8\u9001\u4f1a\u663e\u793a\u6d88\u606f\u680f\uff0c\u5982\u679c\u7528\u6237\u70b9\u51fb\u901a\u77e5\uff0capp\u4f1a\u663e\u793a\u5728\u524d\u53f0\uff0c\u901a\u77e5\u5185\u5bb9\u4f1a\u88abJS\u56de\u8c03\u63a5\u6536\u3002\u5982\u679c\u4e0d\u70b9\u51fb\u6216\u5173\u95ed\uff0c\u901a\u77e5\u5c06\u4e00\u76f4\u5b58\u5728\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u6211\u4eec\u9879\u76ee\u4e2d\u4f7f\u7528\u7684\u662f<a href=\"https:\/\/github.com\/dpa99c\/cordova-plugin-firebasex\">cordova-plugin-firebasex<\/a> \uff0c\u6709\u4e2abug\uff0c\u624b\u673a\u606f\u5c4f\u63a5\u6536\u6d88\u606f\u5f88\u5feb\uff0c\u4eae\u5c4fapp\u540e\u53f0\u8fd0\u884c\u63a5\u6536\u4e0d\u7a33\u5b9a\u3002<\/p>\n<\/li>\n<li>\n<p>\u5173\u4e8e\u901a\u77e5\u6743\u9650\uff0c\u5bf9\u4e8e\u5b89\u5353\uff0c\u4e0d\u9700\u8981\u6388\u6743\uff0c\u4f46\u662f\u5bf9\u4e8eapple\uff0c\u9700\u8981\u8c03\u7528\u8bf7\u6c42\u6388\u6743\u65b9\u6cd5\uff0c\u5982\u6211\u4eec\u7528\u5230\u7684<code>cordova-plugin-firebasex<\/code>\u63d2\u4ef6\u9700\u8981\u8c03\u7528\u63d0\u4f9b\u7684<code>grantpermission<\/code>\u65b9\u6cd5\u3002<\/p>\n<\/li>\n<\/ul>\n<p><img src=\"https:\/\/pic-1301237009.cos.ap-beijing.myqcloud.com\/notes\/20210907172030.png\" alt=\"\" \/><\/p>\n<ul>\n<li>\u4f7f\u7528\u5b89\u5353\u6a21\u62df\u5668\u65f6\u8bb0\u5f97\u9009\u7528\u5e26GooglePlay\u6807\u5fd7\u7684\u7248\u672c\uff0c\u7136\u540e\u9700\u8981\u5728\u66f4\u591a\u8bbe\u7f6e\u91cc\u66f4\u65b0GooglePlay\u7684\u7248\u672c\uff0c\u5e76\u5728\u865a\u62df\u673a\u5185\u90e8\u505a\u4e00\u4e0b\u63a5\u5165\u70b9\u4ee3\u7406\uff0c\u8bb0\u5f97\u52fe\u9009\u4e00\u4e0b\u68af\u5b50\u7684\u5141\u8bb8\u6765\u81ea\u5c40\u57df\u7f51\u7684\u8bbf\u95ee\u3002<\/li>\n<\/ul>\n<p><img src=\"https:\/\/pic-1301237009.cos.ap-beijing.myqcloud.com\/notes\/image-20210909162430813.png\" alt=\"image-20210909162430813\" \/><\/p>\n<ul>\n<li>\n<p>FCM\u53d1\u9001\u63a8\u9001\u5206\u4e09\u79cd\u7c7b\u578b\uff1a<\/p>\n<ul>\n<li>\u6309\u8bbe\u5907ID(\u9488\u5bf9\u6027\u5f3a\uff0c\u53ef\u4ee5\u53ea\u53d1\u7ed9\u67d0\u51e0\u53f0\u8bbe\u5907)\uff0c\u9700\u8981\u4f20<code>device token<\/code><\/li>\n<li>\u6309<code>topic<\/code>\u4e3b\u9898\uff0c\u6bd4\u5982\u5b9a\u4e49\u4e00\u4e2a\u540d\u4e3a<code>ad<\/code>\u7684topic\uff0c\u53ea\u6709\u8ba2\u9605\u8fd9\u4e2atopic\u7684\u8bbe\u5907\u624d\u80fd\u63a5\u6536\u5230\u901a\u77e5<\/li>\n<li>\u6309target\u76ee\u6807\uff0c\u8fd9\u5e94\u8be5\u662ffirebase\u7684\u7279\u8272\uff0c\u4f60\u53ef\u4ee5\u9488\u5bf9\u67d0\u5e73\u53f0(ios\u6216android),\u67d0\u4e2a\u56fd\u5bb6\uff0c\u67d0\u76ee\u6807\u4eba\u7fa4\uff0c\u7b49\u7edf\u8ba1\u76f8\u5173\u53c2\u6570\u53d1\u63a8\u9001\uff0c\u5f88\u7075\u6d3b\u3002\u4f46\u662f\u9700\u8981\u540c\u65f6\u5f00\u542fgoogle analysis<\/li>\n<\/ul>\n<p><img src=\"https:\/\/pic-1301237009.cos.ap-beijing.myqcloud.com\/notes\/20210907171050.png\" alt=\"\" \/><\/p>\n<\/li>\n<li>\n<p>APN(Apple Push Notification)\uff0c\u4e0d\u50cf\u5b89\u5353\u90a3\u4e48\u6df7\u4e71\uff0c\u82f9\u679c\u901a\u77e5\u90fd\u8d70\u7684APN\uff0c\u5927\u81f4\u6d41\u7a0b\uff1afirebase\u901a\u77e5APN\uff0cAPN\u901a\u77e5apple\u8bbe\u5907\u5ba2\u6237\u7aef\u3002<a href=\"https:\/\/developer.apple.com\/documentation\/usernotifications\">\u6280\u672f\u6587\u6863<\/a><\/p>\n<\/li>\n<li>\n<p>\u5bf9\u4e8e\u5b89\u5353\uff0c\u786e\u4fdd\u5728firebase\u9879\u76ee\u8bbe\u7f6e\u4e2d\u751f\u6210\u4e86<code>google-services.json<\/code>\uff0c\u5bf9\u4e8eios\uff0c\u8981\u751f\u6210<code>GoogleService-Info.plist<\/code>\u6587\u4ef6\uff0c\u4ee5\u53ca\u5230\u82f9\u679c\u5f00\u53d1\u8005\u540e\u540e\u53f0\u751f\u6210p8\u6216p12\u6587\u4ef6\u5e76\u4e0a\u4f20\u5230firebase\u9879\u76eeios\u96c6\u6210\u9875\u9762\u4e2d\uff0c\u751f\u6210\u6587\u4ef6\u5728\u653e\u5230cordova\u9879\u76ee\u6839\u76ee\u5f55<br \/>\n\u5efa\u8bae\u751f\u6210P8\u8ba4\u8bc1\u6587\u4ef6\uff0cP12\u6587\u4ef6\u6709\u5f88\u591a\u7f3a\u70b9\uff0c\u7e41\u7410\uff0c\u533a\u5206\u5f00\u53d1\u548c\u6b63\u5f0f\u73af\u5883\uff0c\u800c\u4e14\u8fd8\u6709\u6709\u6548\u671f\uff0c\u751f\u6210\u6d41\u7a0b\u53c2\u89c1:<a href=\"https:\/\/leancloud.cn\/docs\/ios_push_cert.html\">iOS \u63a8\u9001\u8bbe\u7f6e\u6307\u5357<\/a><\/p>\n<\/li>\n<li>\n<p>\u6d88\u606f\u63a8\u9001\u5185\u5bb9\u53ef\u4ee5\u5e26<a href=\"http:\/\/www.unicode.org\/emoji\/charts\/full-emoji-list.html#1f633\">emoji<\/a><\/p>\n<\/li>\n<li>\n<p>\u4f7f\u7528\u547d\u4ee4\u884c\u53d1\u9001\u6d88\u606f<\/p>\n<\/li>\n<\/ul>\n<p><code>Access toke<\/code>\u53ef\u4ee5\u5230 <code>https:\/\/developers.google.com\/oauthplayground<\/code> \u83b7\u53d6<\/p>\n<pre><code class=\"language-shell\">curl -X POST -H &quot;Authorization: Bearer ya29.ElqKBGN2Ri_Uz...HnS_uNreA&quot; -H &quot;Content-Type: application\/json&quot; -d &#039;{\n  &quot;message&quot;: {\n    &quot;topic&quot; : &quot;my-topic&quot;,\n    &quot;notification&quot;: {\n      &quot;body&quot;: &quot;This is a Firebase Cloud Messaging Topic Message!&quot;,\n      &quot;title&quot;: &quot;FCM Message&quot;\n    }\n  }\n}&#039; https:\/\/fcm.googleapis.com\/v1\/projects\/myproject-b5ae1\/messages:send HTTP\/1.1<\/code><\/pre>\n<h2>\u53c2\u8003<\/h2>\n<p><a href=\"https:\/\/juejin.cn\/post\/6844904153274155022\">https:\/\/juejin.cn\/post\/6844904153274155022<\/a><\/p>\n<p><a href=\"https:\/\/github.com\/katzer\/cordova-plugin-local-notifications#readme\">https:\/\/github.com\/katzer\/cordova-plugin-local-notifications#readme<\/a><\/p>\n<p><a href=\"https:\/\/www.npmjs.com\/package\/cordova-plugin-fcm-with-dependecy-updated\">https:\/\/www.npmjs.com\/package\/cordova-plugin-fcm-with-dependecy-updated<\/a><\/p>\n<p><a href=\"https:\/\/developer.apple.com\/documentation\/usernotifications\">https:\/\/developer.apple.com\/documentation\/usernotifications<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Firebase Cloud Messaging (FCM) \u662f\u4e00\u79cd\u8de8\u5e73\u53f0(\u5b89\u5353\uff0cIOS\uff0cWeb)\u6d88\u606f\u4f20\u9012\u89e3\u51b3\u65b9\u6848\uff0c\u4e14\u65e0\u9700\u4efb\u4f55\u8d39\u7528\u3002 \u6700\u8fd1\u7528cordova\u5f00\u53d1app\uff0c\u5ba2\u6237\u5e0c\u671b\u52a0\u5165\u6d88\u606f\u63a8\u9001\u529f\u80fd\uff0c\u56fd\u5185\u6211\u4eec\u2026<\/p>\n","protected":false},"author":1,"featured_media":115,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[2],"tags":[],"blocksy_meta":{"styles_descriptor":{"styles":{"desktop":"","tablet":"","mobile":""},"google_fonts":[],"version":5}},"_links":{"self":[{"href":"https:\/\/blog.osvlabs.com\/index.php?rest_route=\/wp\/v2\/posts\/104"}],"collection":[{"href":"https:\/\/blog.osvlabs.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.osvlabs.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.osvlabs.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.osvlabs.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=104"}],"version-history":[{"count":3,"href":"https:\/\/blog.osvlabs.com\/index.php?rest_route=\/wp\/v2\/posts\/104\/revisions"}],"predecessor-version":[{"id":109,"href":"https:\/\/blog.osvlabs.com\/index.php?rest_route=\/wp\/v2\/posts\/104\/revisions\/109"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.osvlabs.com\/index.php?rest_route=\/wp\/v2\/media\/115"}],"wp:attachment":[{"href":"https:\/\/blog.osvlabs.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=104"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.osvlabs.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=104"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.osvlabs.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=104"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}