简体   繁体   English

使用Ionic应用程序的Firebase云消息传递

[英]Firebase Cloud Messaging with Ionic app

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. 我正在使用离子框架(Web技术)开发android / ios应用程序,我想在新的firebase功能FCM的帮助下添加推送通知。

Right now I am looking at following docs: 现在我正在看以下文档:

https://firebase.google.com/docs/cloud-messaging/chrome/client#project-setup https://firebase.google.com/docs/cloud-messaging/chrome/client#project-setup

that says: 说的是:

  • Websites in Chrome can implement push messaging through service workers and web Chrome中的网站可以通过服务工作者和网络实现推送消息传递
  • app manifests following the Webpush standard. 应用程序符合Webpush标准。 Chrome apps and extensions can access the FCM service directly through chrome.gcm Chrome应用和扩展程序可以直接通过chrome.gcm访问FCM服务
    API. API。

Does it mean I can use it in my ionic app for both android/ios, since app is built using cordova? 这是否意味着我可以在我的离子应用程序中使用它同时用于android / ios,因为app是使用cordova构建的?

Also it will be very helpful if there is any implemented example, I can see and learn from. 如果有任何实现的例子,我可以看到和学习​​,这将是非常有帮助的。

Thanks 谢谢

I know this question is jurassic already but just for information of future mobile developers using Ionic framework. 我知道这个问题已经是侏罗纪了,但仅仅是为了使用Ionic框架的未来移动开发者的信息。 This is 100% working now, I've been using it for the past 3 weeks. 这是100%现在工作,我在过去3周一直在使用它。

All you need is to add these 3 plugins 您只需添加这3个插件即可

⁠⁠⁠ionic plugin add cordova-plugin-inappbrowser
ionic plugin add cordova-plugin-fcm
ionic plugin add cordova-plugin-velda-devicefeedback

Next, go to Firebase Console and 接下来,转到Firebase控制台

  • Create a New Project and give it a name; 创建一个新项目并为其命名;
  • Select which platform you like (ios/android); 选择你喜欢的平台(ios / android);
  • Add your Package Name , which is the id of your app: you can see it in your config.xml (something like id="com.ionicframework.someTest123" ). 添加您的包名称 ,这是您的应用程序的ID:您可以在config.xml中看到它(类似于id =“com.ionicframework.someTest123” )。

The Firebase Console will give you a file named google-services.json . Firebase控制台会为您提供名为google-services.json的文件。

  • Paste it in the platforms/android/ directory 将其粘贴到platforms / android /目录中
  • Run ionic build android on your CLI 在CLI上运行ionic build android

You can now go to Notifications Page > New Message 您现在可以转到通知页面>新消息

Make sure to select the app (id of the app) you added before sending push notifications. 确保在发送推送通知之前选择您添加的应用程序(应用程序的ID)。

I managed to get it work work on IOS. 我设法让它在IOS上工作。 Here's what I did. 这就是我做的。

  1. Go to Firebase and add a new IOS app for cloud messaging. 转到Firebase并添加新的IOS应用程序以进行云消息传递。 Follow the instructions and fill up the simple form for your app ID etc. You will generate the GoogleServices-Info.plist file and download. 按照说明填写您的应用ID等的简单表格。您将生成GoogleServices-Info.plist文件并下载。 Ignore the cocoapods stuff. 忽略cocoapods的东西。 You don't need it. 你不需要它。

  2. Navigate to your Ionic app platforms/ios and open the xcodeproject file with XCode. 导航到您的Ionic app平台/ ios并使用XCode打开xcodeproject文件。

  3. Paste thedownloaded GoogleServices plist file to the root of your Xcode project file. 将下载的GoogleServices plist文件粘贴到Xcode项目文件的根目录中。

  4. Run. 跑。 Or you can try saving then do ionic build ios , ionic emulate ios . 或者你可以尝试保存然后做ionic build iosionic emulate ios

I added the old phonegap-plugin-push earlier. 我之前添加了旧的phonegap-plugin-push。 This had to be removed from my config.xml or else the IOS won't build successfully. 这必须从我的config.xml中删除,否则IOS将无法成功构建。

You can use FCM with cordova without a problem but it requires writing native code for Android, iOS and other platforms you want to use. 您可以在没有问题的情况下使用带有cordova的FCM,但它需要为Android,iOS和您要使用的其他平台编写本机代码。 Luckily the cordova community is pretty big and the work is already done. 幸运的是,科尔多瓦社区非常庞大,工作已经完成。 The following plugin states to do exactly what you want. 以下插件声明可以完全按照您的要求执行操作。

https://www.npmjs.com/package/cordova-plugin-fcm https://www.npmjs.com/package/cordova-plugin-fcm

I haven't tried the plugin myself yet but the readme says you can subscribe to topics from javascript and call the onNotification function to listen for notifications, handy when your app is in foreground. 我自己还没有尝试过这个插件,但自述文件说你可以订阅javascript中的主题并调用onNotification函数来监听通知,当你的应用程序在前台时很方便。

The FCM support for JS/browser relies on the browser's notification API's, of which I don't believe cordova has one that will work natively. 对JS /浏览器的FCM支持依赖于浏览器的通知API,我不相信cordova有一个可以原生工作的API。 You can and should use FCM for all platforms but you'll have to work through adding support for each platform manually or wait for the push plugin development. 您可以而且应该在所有平台上使用FCM,但您必须手动添加对每个平台的支持或等待推送插件开发。

The phonegap push plugin is being updated to support FCM: Migrate to Firebase Cloud Messaging #929 正在更新phonegap推送插件以支持FCM: 迁移到Firebase云消息传递#929

Alternatively you can use the old GCM platform with the phonegap plugin already but you'll want to update your server side push API to use FCM as soon as the plugin is ready. 或者,您可以将旧的GCM平台与phonegap插件一起使用,但是您需要在插件准备就绪后立即更新服务器端推送API以使用FCM。

您可以查看:适用于iOS和Android https://github.com/mail2lulu/cordova-plugin-fcm.git

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

相关问题 Cordova应用程序中的Firebase云消息传递 - Firebase cloud messaging in cordova app 在Ionic框架中使用Firebase Cloud Messaging插件的步骤 - Step using Firebase Cloud Messaging Plugin in ionic framework 使用Firebase云消息传递的离子本机推送崩溃 - Ionic Native Push Crashes using Firebase Cloud Messaging 使用Frirebase云消息传递与离子应用程序的用户到用户通知消息 - user to user notification message with ionic app using Frirebase cloud Messaging Windows Mobile App(Cordova)中的FCM(Firebase云消息传递)? - FCM (Firebase Cloud Messaging) in Windows Mobile App (Cordova)? 使用Ionic Native Push获取Firebase Cloud Messaging的正确FCM注册令牌 - Getting the correct FCM Registration Token for Firebase Cloud Messaging using Ionic Native Push IOS Firebase 云消息“InvalidApnsCredential” - IOS Firebase Cloud Messaging "InvalidApnsCredential" 带有Firebase消息传递和Firebase动态链接的Cordova Ionic项目 - Cordova Ionic project with Firebase Messaging and Firebase Dynamic Links 使用cordova-plugin-firebase-messaging显示来自Ionic的通知 - Displaying notifications from Ionic using cordova-plugin-firebase-messaging 使用cordova和firebase推送通知云消息:registrationID不断变化 - push notification with cordova and firebase Cloud messaging:registrationID keep changing
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM