简体   繁体   English

Ionic 框架的推送通知

[英]Push Notifications for Ionic Framework

Back again.再次回来。 I'm writing a mobile application for Android and iOS using ionic framework.我正在使用离子框架为 Android 和 iOS 编写移动应用程序。 It is working well so far as I have the flexibility I want to write it.就我想要编写它的灵活性而言,它运行良好。 I've come up to the point of having to add push notifications and chose to use the Azure Notification Service seeing as I'm hosting everything else in Azure too.我已经到了不得不添加推送通知的地步,并选择使用 Azure 通知服务,因为我也在 Azure 中托管其他所有内容。

I've followed the examples in the repo as suggested by Microsoft here but they are out of date.我按照 Microsoft 此处的建议遵循了存储库中的示例,但它们已经过时了。 They are all for Ionic 4 and it is now Ionic 6. The phone-gap plugin is now out of support and the example code doesn't work (due to the fact that the framework has now moved on).它们都适用于 Ionic 4,现在是 Ionic 6。phone-gap 插件现在不受支持,示例代码也不起作用(由于框架现在已经转移)。

I'm hoping and praying that someone has an example they could share of how to achieve this.我希望并祈祷有人有一个他们可以分享如何实现这一目标的例子。

Thanks in advance.提前致谢。

Maybe it's not the best solution, but it works:也许这不是最好的解决方案,但它有效:

In case you cannot manage to get Azure Notification Service working, you can connect your Azure service to Google push notifications API .如果您无法使Azure Notification Service正常工作,您可以将 Azure 服务连接到Google push notifications API

You only have to make a post request to https://fcm.googleapis.com/fcm/send .您只需向https://fcm.googleapis.com/fcm/send发出发帖请求。

https://firebase.google.com/docs/cloud-messaging/send-message#send_using_the_fcm_v1_http_api https://firebase.google.com/docs/cloud-messaging/send-message#send_using_the_fcm_v1_http_api

Here you have an example that I've used:这里有一个我用过的例子:

#!/bin/bash

curl -d '{
  "to": "USER_NOTIFICATIONS_TOKEN",
   "notification": {
   },
   "data":
    {
      "data1":"qwertyu",
      "data2":"4567893",
    }
}' \
-i -H "Application/json" \
-H "Content-type: application/json" \
-H "Authorization: key=MY_SECRET_KEY" \
-X POST https://fcm.googleapis.com/fcm/send

Then, to receive the notifications by cordova, you can use this library:然后,要接收 cordova 的通知,您可以使用此库:

https://github.com/Maxim-Kolmogorov/cordova-plugin-push-notifications

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM