如何在手机缺口中使用本地通知?

问题描述 投票:0回答:1

大家好,我是电话界的初学者

我想使用移动本地通知并搜索很多插件

使用手机间隙本地通知和其他插件,遗憾的是一切都无法正常工作

现在我正在尝试使用cordova插件

这是我的js代码

document.addEventListener('deviceready', onDeviceReady, false);
function onDeviceReady() {
    alert('1');
    cordova.plugins.notification.local.schedule({
        title: 'My first notification',
        text: 'Thats pretty easy...',
        foreground: true
    });
    alert('2')
}

HTML

脚本

 <script type="text/javascript" src="js/jquery-3.2.1.min.js"></script>
        <script type="text/javascript" src="cordova.js"></script>
        <script type="text/javascript" src="js/index.js"></script>

config.xml中

 <plugin name="cordova-plugin-file-transfer2" spec="^1.0.1" />
    <plugin name="phonegap-plugin-push" spec="^2.1.2">
        <variable name="FCM_VERSION" value="11.0.1" />
    </plugin>
    <plugin name="phonegap-plugin-local-notification" spec="^1.0.1" />
    <plugin name="cordova-plugin-local-notification" spec="^0.9.0-beta.2" />
    <gap:plugin name="de.appplant.cordova.plugin.local-notification" />

第一个警报出现,但第二个没有出现

我该怎么做才能实现这一目标

感谢大家

cordova phonegap-plugins cordova-plugins phonegap
1个回答
0
投票

使用以下代码。

在你的config.xml中

 <plugin spec=" https://github.com/acianti/cordova-plugin-local-notifications.git" />

这是脚本代码

   var alarmTime = new Date();

   alarmTime.setMinutes(alarmTime.getMinutes() + 1);

cordova.plugins.notification.local.registerPermission(function (str) {


   cordova.plugins.notification.local.schedule({
    id: '1',
    title: 'Test Notification',
    message: 'Hello',
    date: alarmTime
    });
});
© www.soinside.com 2019 - 2024. All rights reserved.