本文介绍了Android上具有Firebase Cloud的Adobe Phonegap推送通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

自2018年以来,标准的Phonegap推送通知示例项目不再起作用.我正在努力寻找一种将推送通知发送到应用程序的实用方法.到目前为止,我已经执行了以下操作:

Since 2018 the standard Phonegap push notifiction sample project no longer works.I am struggling to find a functional way to send a push notification to an app.So far I have done the following:

  1. 设置Adobe Phonegap推送通知示例项目
  2. 设置一个Firebase Cloud帐户并创建一个项目并添加一个可以使用Android应用程序.
  3. 下载了google-services.json
  4. 安装了phonegap-plugin-push(1.8.0,显然超过2.0都有问题),并且包含了我的发件人ID
  5. 已安装cordova-android-support-gradle-release,cordova-android-play-services-gradle-release和cordova-android-firebase-gradle-release
  6. 修正了index.js,以便不再在Android PushNotification.init对象中发送发件人ID(显然不再需要)
  7. 修正了index.js,使pushServiceURL包含在PushNotification.init浏览器对象中(显然,这是在浏览器中进行测试所必需的)
  8. 在Firebase云中设置并发布推送消息广告系列,以在打开应用程序时触发
  1. Set up the Adobe Phonegap push notification sample project
  2. Set up a Firebase Cloud account and created a project and added anAndroid app to it.
  3. Downloaded the google-services.json
  4. Installed phonegap-plugin-push (1.8.0 as apparently anything over 2.0 has problems), and included my Sender ID
  5. Installed cordova-android-support-gradle-release, cordova-android-play-services-gradle-release and cordova-android-firebase-gradle-release
  6. Amended the index.js so that the sender ID is no longer sent in the PushNotification.init Android object (apparently no longer required)
  7. Amended the index.js so that the pushServiceURL is included in the PushNotification.init Browser object (apparently this IS required for testing in the browser)
  8. Set up and published a push message campaign in Firebase cloud, to trigger when app is opened

我正在使用Android 8.1.0.我已经安装了Adobe Phonegap Developer App

I am using Android 8.1.0. I have installed the Adobe Phonegap Developer App

结果:我在CLI中运行Phonegap服务.我在CLI中看到以下内容:

Result:I run Phonegap serve in the CLI.I see the following in my CLI:

Updating manifest.json with push properties…
[phonegap] starting app server...
[phonegap] listening on 192.168.1.57:3000
[phonegap]
[phonegap] ctrl-c to stop the server
[phonegap]
Updating manifest.json with push properties…
Manifest updated with push sender ID
Manifest updated with push sender ID
[phonegap] 200 /socket.io/?EIO=3&transport=polling&t=MbsZP-M
[phonegap] 200 /socket.io/?
EIO=3&transport=polling&t=MbsZSMw&sid=Wyc9htsKdIkXHCtKAAAA
[phonegap] 200 /__api__/update
[phonegap] 200 /__api__/update
[phonegap] 200 /__api__/update
[phonegap] 200 /socket.io/socket.io.js

...到目前为止一切都很好.我在Android设备上加载了Phonegap Developer应用并进行连接,然后看到:

...everything looks good so far. I load up the Phonegap Developer App on my Android device and connect and I see:

[phonegap] [console.warn] Content Security Policy has been modified to be:
<meta http-equiv="Content-Security-Policy" content="default-src * 'unsafe-inline' gap: ws: https://ssl.gstatic.com;style-src 'self' 'unsafe-inline' data: blob:;media-src *;img-src * 'self' data: content:;script-src * 'unsafe-inline' 'unsafe-eval' data: blob:;">
[phonegap] [console.warn] Content Security Policy has been added: <meta http-equiv="Content-Security-Policy" content="default-src * gap: ws: https://ssl.gstatic.com;img-src * 'self' data: content:;style-src 'self' 'unsafe-inline' data: blob:;script-src * 'unsafe-inline' 'unsafe-eval' data: blob:;">
[phonegap] 200 /__api__/appzip
[phonegap] 200 /socket.io/socket.io.js
[phonegap] 200 /socket.io/?EIO=3&transport=polling&t=MbsaRlk
[phonegap] 200 /socket.io/?EIO=3&transport=polling&t=MbsaRmS&sid=R8RzNxpm8Z-XkKNtAAAD
[phonegap] [console.log] Received Device Ready Event
[phonegap] [console.log] calling setup push
[phonegap] [console.log] calling push init
[phonegap] [console.log] after init
[phonegap] [console.log] Device Push ID:
[phonegap] dijoTzuKUVd:APA91dERSwx0ZeKAg2nqeOCTJnXkeuBqQQQrJgGi4c0m5I_G30IjF6IiHex8Muazj-QlNVmemqPf0dQQgvF0u5eJPMQ-VTTagpGVnQvgqZUEUSlzKnAabrw4kz0W45RnrsbJNKAbFZbh
[phonegap] [console.log] registration event: dijoTzuKUVd:APA91dERSwx0ZeKAg2nqeOCTJnXkeuBqQQQrJgGi4c0m5I_G30IjF6IiHex8Muazj-QlNVmemqPf0dQQgvF0u5eJPMQ-VTTagpGVnQvgqZUEUSlzKnAabrw4kz0W45RnrsbJNKAbFZbh

...再次,一切看起来都很好,并且屏幕上的消息显示为已注册".因此一切正常,除非未收到任何消息.而且没有控制台日志可通知我任何消息尝试.

...again, everything looks good, and the message on the screen says "registered". so everything seems ok except no message is received. And no console log to inform me of any message attempt.

我还尝试使用Firebase实例ID添加测试设备.从我的代码中,我假设"dijoTzuKUVd:APA91dERSwx0ZeKAg2nqeOCTJnXkeuBqQQQrJgGi4c0m5I_G30IjF6IiHex8Muazj-QlNVmemqPf0dQQgvF0u5eJPMQVTZbznZeZaZnZeZaZnZeZaZnZeZaZnZeZaZnZeZaZnZeA因此,我补充了一点,但Firebase表示这是无效格式".然后,我只尝试了Firebase接受的冒号("dijoTzuKUVd")之前的代码(但不知道这样做是否正确),然后尝试再次发送该消息.但还是一无所有.

I have also tried to add test device using the Firebase instance ID. From my code I assume "dijoTzuKUVd:APA91dERSwx0ZeKAg2nqeOCTJnXkeuBqQQQrJgGi4c0m5I_G30IjF6IiHex8Muazj-QlNVmemqPf0dQQgvF0u5eJPMQ-VTTagpGVnQvgqZUEUSlzKnAabrw4kz0W45RnrsbJNKAbFZbh" is the test device? So I add that but Firebase says it is an "invalid format". I then tried just the code before the colon ("dijoTzuKUVd") which Firebase accepted (but no idea if that is right) and tried to send the message again. But still nothing.

有人知道我在想什么吗?

Does anybody know what I am missing?

除此之外,当我在任何浏览器中运行该应用程序时,都会出现JS错误:

ADDITIONAL to this, when I run the app in any browser I get the JS error:

Uncaught Error: Service Workers are not supported on your browser.
at new PushNotification (push.js:89)
at Object.init (push.js:366)
at Object.setupPush (index.js:42)
at Channel.onDeviceReady (index.js:38)
at Channel.fire (cordova.js:798)
at cordova.js:229

...所以我也无法在浏览器上对其进行测试.

...so I can't test it on the browser either.

任何帮助表示赞赏.

推荐答案

通过本地服务器进行测试时,Adobe Phonegap不再支持通知.

Adobe Phonegap no longer supports notifications when testing through the local server.

我最终使用了phonegap-plugin-push库来接收来自FCM的推送通知.

I ended up using the phonegap-plugin-push library to receive push notifications from FCM.

https://github.com/phonegap/phonegap-plugin-push

这篇关于Android上具有Firebase Cloud的Adobe Phonegap推送通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-06 01:35