Javascript 使用离子电容器和框架设置本地通知7
我使用离子电容器和框架7进行应用。我想使用电容器本地通知插件实现本地通知。但是,它给了我未捕获的引用错误:未定义LocalNotificationsJavascript 使用离子电容器和框架设置本地通知7,javascript,html-framework-7,capacitor,Javascript,Html Framework 7,Capacitor,我使用离子电容器和框架7进行应用。我想使用电容器本地通知插件实现本地通知。但是,它给了我未捕获的引用错误:未定义LocalNotifications //Importing plugin import {Plugins} from '../node_modules/@capacitor/core'; const {LocalNotifications} = Plugins; //Schedule Local Notifcations LocalNotifications.schedul
//Importing plugin
import {Plugins} from '../node_modules/@capacitor/core';
const {LocalNotifications} = Plugins;
//Schedule Local Notifcations
LocalNotifications.schedule({
notifications: [{
title: "Title",
body: "Body",
id: 1,
schedule: {
at: new Date(Date.now() + 1000 * 5)
},
sound: 'res://audio/android/iphone_6.mp3',
attachments: null,
actionTypeId: "",
extra: null
}]
});
未捕获引用错误:未定义LocalNotifications尝试从“@capactor/core”导入
插件
如导入{Plugins}代码>只是在@igor\u c提到的插件导入方式的基础上进行构建。您需要像上面建议的那样导入插件,然后从const{LocalNotifications}=Plugins这样的插件中提取LocalNotifications实例
我在Android上也遇到了同样的问题,这个解决方案解决了这个问题,我认为这与vscode导入libs的方式有关。。。
//Importing plugin
import {Plugins} from '../node_modules/@capacitor/core';
const {LocalNotifications} = Plugins;
//Schedule Local Notifcations
LocalNotifications.schedule({
notifications: [{
title: "Title",
body: "Body",
id: 1,
schedule: {
at: new Date(Date.now() + 1000 * 5)
},
sound: 'res://audio/android/iphone_6.mp3',
attachments: null,
actionTypeId: "",
extra: null
}]
});