电容器-在Ionic+Angular应用程序中未接收推送通知



我已经开始使用电容器了。阅读后https://capacitorjs.com/docs/cordova/known-incompatible-plugins我发现电容器不支持某些cordova插件。

我在我的推送通知应用程序中使用了cordova插件fcm,android版和iOS版分别更新了和https://capacitorjs.com/docs/apis/push-notifications#addlistener.

本机方法不会引发任何错误,我也可以获得注册的令牌,但我不会在注册的设备上收到推送通知。

我也试过https://www.npmjs.com/package/capacitor-fcm但是CCD_ 1返回空。

电容器.config.son

"plugins": {
"PushNotifications": {
"presentationOptions": [
"badge",
"sound",
"alert"
]
}
}

应用

@Component({
selector: 'app-root',
templateUrl: 'app.component.html'
})
export class AppComponent implements OnInit {
constructor(
private platform: Platform,
private splashScreen: SplashScreen,
private fcmService: FcmService
) {
this.initializeApp();
}
ngOnInit() {}
initializeApp() {
this.platform.ready().then(() => {  
setTimeout(() => {
this.splashScreen.hide();
}, 300);    
this.fcmService.initPush();
});
}
}

fcm.services.ts

import { Injectable } from '@angular/core';
import {
Plugins,
PushNotification,
PushNotificationToken,
PushNotificationActionPerformed,
Capacitor
} from '@capacitor/core';
import { Router } from '@angular/router';
const { PushNotifications, Modals } = Plugins;
import { FCM } from '@capacitor-community/fcm';
const fcm = new FCM();
const { FCMPlugin } = Plugins;
@Injectable({
providedIn: 'root'
})
export class FcmService {

constructor(
private router: Router) { }
initPush() {
alert('Capacitor platform' + Capacitor.platform);
if (Capacitor.platform !== 'web') {
this.registerPush();
}
}
private registerPush() {
PushNotifications.requestPermission().then((permission) => {
if (permission.granted) {
// Register with Apple / Google to receive push via APNS/FCM
PushNotifications.register();
} else {
alert('No permission for push granted');
}
});
PushNotifications.addListener(
'registration',
(token: PushNotificationToken) => {
alert('APN token: ' + JSON.stringify(token));
fcm.getToken().then((r) => {
alert(`FCM Token: ${r.token}`); //---- showing null.
}).catch((err) => {
alert(`FCM Token ERROR: ${JSON.stringify(err)}`);
});
}
);
PushNotifications.addListener('registrationError', (error: any) => {
alert('Registration Error: ' + JSON.stringify(error));
});
PushNotifications.addListener(
'pushNotificationReceived',
async (notification: PushNotification) => {                    
Modals.alert({
title: notification.title,
message: notification.body
})
}
);
PushNotifications.addListener(
'pushNotificationActionPerformed',
async (notification: PushNotificationActionPerformed) => {
alert('Action performed: ' + JSON.stringify(notification.notification));
}
);
}
}

我有没有遗漏什么,或者我需要添加额外的配置来接收推送通知?

您在firebase项目中添加了SHA certificate fingerprints并更新了谷歌服务文件?

最新更新