ionic-framework - 离子反应本地通知与电容器不工作
问题描述
我正在尝试使用电容器实现本地通知。
首先我使用以下命令安装插件,
npm install @ionic-native/local-notifications
npm install cordova-plugin-local-notification
然后在我的 .js 文件中,我确实添加了以下代码
import { Plugins } from '@capacitor/core';
和
scheduleNotification = () => {
Plugins.LocalNotifications.schedule({
notifications: [
{
title: "Title",
body: "Body",
id: 1,
schedule: { at: new Date(Date.now() + 1000 * 5) },
sound: null,
attachments: null,
actionTypeId: "",
extra: null
}
]
});
console.log('scheduled notifications');
}
我尝试了所有方法,但在运行 iOS 12 的 iPhone 6s 上看不到任何本地通知。当我检查 Xcode 日志时,我可以看到 id 为 1 的计划通知。
cordova-plugin-badge (0.8.8)
cordova-plugin-device (2.0.3)
cordova-plugin-local-notification (0.9.0-beta.2)
解决方案
这是关于您的结果中的 id pass 的问题。
PushNotifications.addListener('pushNotificationReceived',
async (notification: any) => {
console.log(notification);
const notifs = await LocalNotifications.schedule({
notifications: [
{
title: notification.title,
body: notification.body,
id: new Date().getTime(),
schedule: { at: new Date(Date.now() + 1000 * 5) },
sound: this.platform.is("android")
? "file://sound.mp3"
: "file://beep.caf",
attachments: null,
actionTypeId: "",
extra: notification
}
]
});
}
);
推荐阅读
- android - 如何从另一个片段更新视图模型?
- c# - 带有 StackOverflowException 的错误类 C# 在做什么
- android - 房间不返回重复项
- python - 关于碰撞检测和更新标签的说明
- html - 输入更多类型时使 HTML 输入字体大小缩小
- python-3.x - 如何重命名小提琴图中的x标签?
- node.js - 使用 PHP API 和 APache 服务器在 Digitalocean 上部署 ReactJs 应用程序
- javascript - 当有人点击网站上的任何位置时,活动和焦点课程将被删除
- node.js - 如何将数据从 AWS API Gateway 自定义授权方传递到 AWS Lambda 函数?
- python - 100 天的 Python - 无法复制