问题描述
大家好,我正在将应用程序从ionic 1迁移到ionic 5,并且需要集成pushwoosh通知服务,我的项目开始时未使用cordova,而是使用电容器,并且找不到有关的信息。如何将该服务集成到ionic 5应用程序中。
请,我们已经知道您可以使用cordova了,但是在使用cordova plugin add pushwoosh-cordova-plugin@8.0.0
时,它会向您显示以下消息:
Current working directory is not a Cordova-based project.
因为正如我之前所说的,这是一个电容器项目,而不是Cordovan项目,顺便说一句,我已经使用了ionic integrations enable cordova
所以...如果有人可以帮助我们,那将非常有帮助。
解决方法
好几个小时,对我来说,将Pushwoosh集成到ionic 5应用程序中是不可能的,
如果一切设置正确,则会发生以下情况:
- 您的应用将正确连接到Pushwoosh
- 您的应用程序将在pushwoosh中正确注册您的设备
但是您的应用程序将无法收听正式的Pushwoosh文档提供的侦听器
document.addEventListener('push-receive',function (event) {
var message = (<any>event).notification.message;
var userData = (<any>event).notification.userdata;
alert("Push message received: " + message);
console.info(JSON.stringify((<any>event).notification));
//dump custom data to the console if it exists
if (typeof (userData) != "undefined") {
console.warn('user data: ' + JSON.stringify(userData));
}
}
);
这不适用于ionic 5应用程序??
这确实有效:
import { Component,OnInit } from '@angular/core';
import {
Plugins,PushNotification,PushNotificationToken,PushNotificationActionPerformed,} from '@capacitor/core';
const { PushNotifications } = Plugins;
@Component({
selector: 'app-home',templateUrl: 'home.page.html',styleUrls: ['home.page.scss'],})
export class HomePage implements OnInit {
ngOnInit() {
console.log('Initializing HomePage');
// Request permission to use push notifications
// iOS will prompt user and return if they granted permission or not
// Android will just grant without prompting
PushNotifications.requestPermission().then(result => {
if (result.granted) {
// Register with Apple / Google to receive push via APNS/FCM
PushNotifications.register();
} else {
// Show some error
}
});
PushNotifications.addListener(
'registration',(token: PushNotificationToken) => {
alert('Push registration success,token: ' + token.value);
},);
PushNotifications.addListener('registrationError',(error: any) => {
alert('Error on registration: ' + JSON.stringify(error));
});
PushNotifications.addListener(
'pushNotificationReceived',(notification: PushNotification) => {
alert('Push received: ' + JSON.stringify(notification));
},);
PushNotifications.addListener(
'pushNotificationActionPerformed',(notification: PushNotificationActionPerformed) => {
alert('Push action performed: ' + JSON.stringify(notification));
},);
}
}
我尝试将Pushwoosh与电容器结合使用,但是生成的设备的令牌不同,因此我仍然没有收到通知。
在一天结束时,经过许多小时和几天的工作之后,我除了使用firebase别无选择,现在一切都变得更好了。