android - 在 Android 上实现推送通知时出错
问题描述
我正在创建一个离子角度应用程序。我尝试将推送通知与电容器插件一起使用。但是我遇到了这样的错误。谁能帮我?
**"ERROR Error: Uncaught (in promise): Error: "PushNotifications" plugin is not implemented on android
Error: "PushNotifications" plugin is not implemented on android"**
解决方案
我解决了“错误错误:未捕获(承诺):错误:“PushNotifications”插件未在 android 上实现错误:“PushNotifications”插件未在 android 上实现”错误请按照以下步骤操作
在 android/app 文件夹中添加 google-service.json 文件
在 .ts 文件中添加此代码
import {
ActionPerformed,
PushNotificationSchema,
PushNotifications,
Token,
} from '@capacitor/push-notifications';
import { Platform } from '@ionic/angular';
constructor(public platform: Platform) {
this.platform.ready().then(() => {
this.pushAdded();
})
}
pushAdded() {
// 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.requestPermissions().then(result => {
if (result.receive === 'granted') {
// Register with Apple / Google to receive push via APNS/FCM
PushNotifications.register();
} else {
// Show some error
}
});
PushNotifications.addListener('registration', (token: Token) => {
alert('Push registration success, token: ' + token.value);
});
PushNotifications.addListener('registrationError', (error: any) => {
alert('Error on registration: ' + JSON.stringify(error));
});
PushNotifications.addListener(
'pushNotificationReceived',
(notification: PushNotificationSchema) => {
alert('Push received: ' + JSON.stringify(notification));
},
);
PushNotifications.addListener(
'pushNotificationActionPerformed',
(notification: ActionPerformed) => {
alert('Push action performed: ' + JSON.stringify(notification));
},
);
}
推荐阅读
- java - 服务类的 @Transactional 未在测试上下文中调用
- nativescript - 如何限制 Nativescript 仅针对 x86_64 进行编译?
- javascript - 在Bootstrap 4中制作最右边的列固定位置
- hadoop - 从本地主机调用,连接异常失败
- java - 二维数组的数组索引超出边界异常
- mysql - 如何在执行多个联接时从单个表中计数
- css - 如何将鼠标悬停在元素上并更改远祖的样式?
- wordpress - 当变量值在单词之间有空格时,不会在 WP_Query 中显示任何结果
- web - 如果已安装相同的应用程序,Chrome 扩展禁用应用程序
- rxjs - 在 Angular 6 中使用 rxjs 可观察对象的目的是什么?与 async/await 相比,rxjs 的优势是什么?