【发布时间】:2020-04-21 23:41:03
【问题描述】:
我是 Ionic 开发的新手。在过去的几个小时里,我一直在为我的应用程序使用 Ionic2 并尝试添加推送通知 (FCM)。但是,我一直在添加推送配置。以下是详细信息:
"phonegap-plugin-push": "^2.0.0"在我的 package.json 文件中配置。还有原生推送插件"@ionic-native/push": "^4.3.1"-
在 config.xml 中,我添加了
<resource-file src="google-services.json" target="google-services.json" />。还添加了<plugin name="phonegap-plugin-push" spec="^2.0.0" />。3.这是我在主要组件文件中使用的代码:
const options: PushOptions = { android: { topics: ['topic1'] }, ios: { alert: 'true', badge: true, sound: 'false' }, windows: {}, browser: { pushServiceURL: 'http://push.api.phonegap.com/v1/push' } }; const pushObject: PushObject = this.push.init(options); pushObject.on('notification').subscribe((notification: any) => { if (notification.additionalData.foreground) { let pushAlert = this.alertCtrl.create({ title: 'BrainCal Notification', message: notification.message.title }); pushAlert.present(); } }); pushObject.on('registration').subscribe((registration: any) => { //do whatever you want with the registration ID }); pushObject.on('error').subscribe(error => alert('Error with Push plugin' + error));
它已成功部署在我的 Android 手机中。但是,第一次打开应用程序时返回以下错误:
"Error with Push plugin no senderID value given".
据我了解,最新的电话间隙插件不需要 senderID,因为它使用 Google-services.json 文件。请指教。
【问题讨论】:
-
尝试在
config.xml中添加<plugin name="phonegap-plugin-push" spec="^2.0.0" > <variable name="SENDER_ID" value="XXXXXXXXXXXX" /> </plugin> -
已经试过了,没有任何运气。
-
android: { senderID: "XXXXXXXXXXXX",topics: ['topic1'] }试试这个。 -
在最新版本的推送插件中,这个键(“senderID”)不是“接口AndroidPushOptions”的一部分。所以不能用了
标签: ionic2