问题描述
我正在使用 ionic 框架(网络技术)开发 android/ios 应用程序,我想借助新的 firebase 功能 FCM 添加推送通知.
I am developing android/ios app using ionic framework (web technologies) and I want to add Push Notification with the help of new firebase feature FCM.
现在我正在查看以下文档:
Right now I am looking at following docs:
https://firebase.google.com/docs/云消息/chrome/client#project-setup
说:
- Chrome 中的网站可以通过 Service Worker 和 Web 实现推送消息
- 应用清单遵循 Webpush 标准.Chrome 应用和扩展程序可以直接通过 chrome.gcm 访问 FCM 服务
API.
这是否意味着我可以在适用于 android/ios 的 ionic 应用中使用它,因为应用是使用 cordova 构建的?
如果有任何实现的示例,我可以看到并从中学习,这将非常有帮助.
Also it will be very helpful if there is any implemented example, I can see and learn from.
谢谢
推荐答案
我知道这个问题已经是侏罗纪了,但只是为未来使用 Ionic 框架的移动开发人员提供信息.现在可以 100% 工作了,过去 3 周我一直在使用它.
I know this question is jurassic already but just for information of future mobile developers using Ionic framework. This is 100% working now, I've been using it for the past 3 weeks.
你只需要添加这 3 个插件
All you need is to add these 3 plugins
ionic plugin add cordova-plugin-inappbrowser
ionic plugin add cordova-plugin-fcm
ionic plugin add cordova-plugin-velda-devicefeedback
接下来,转到 Firebase 控制台 和
- 创建一个新项目并为其命名;
- 选择你喜欢的平台(ios/android);
- 添加您的包名,这是您的 id应用程序:您可以在 config.xml 中看到它(类似于id="com.ionicframework.someTest123").
- Create a New Project and give it a name;
- Select which platform you like (ios/android);
- Add your Package Name, which is the id of yourapp: you can see it in your config.xml (something likeid="com.ionicframework.someTest123").
Firebase 控制台将为您提供一个名为 google-services.json 的文件.
The Firebase Console will give you a file named google-services.json .
- 将其粘贴到 platforms/android/ 目录中
- 在您的 CLI 上运行
ionic build android
您现在可以前往通知页面 > 新消息
You can now go to Notifications Page > New Message
确保在发送推送之前选择您添加的应用程序(应用程序的 ID)通知.
Make sure to select the app (id of the app) you added before sending push notifications.
这篇关于Firebase 云消息与 Ionic 应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!