如何使用cordova删除显示的通知

如何使用cordova删除显示的通知,cordova,localnotification,Cordova,Localnotification,如何删除已显示(在电话栏上显示)但用户未响应的通知?使用科尔多瓦 我检查了不同的方法,但没有得到它的任何属性或函数。虽然注册时 window.plugin.notification.local.add({ id: String, // A unique id of the notification date: Date, // This expects a date object message: String, // The

如何删除已显示(在电话栏上显示)但用户未响应的通知?使用科尔多瓦

我检查了不同的方法,但没有得到它的任何属性或函数。虽然注册时

window.plugin.notification.local.add({
    id:         String,  // A unique id of the notification
    date:       Date,    // This expects a date object
    message:    String,  // The message that is displayed
    title:      String,  // The title of the message
    repeat:     String,  // Either 'secondly', 'minutely', 'hourly', 'daily', 'weekly', 'monthly' or 'yearly'
    badge:      Number,  // Displays number badge to notification
    sound:      String,  // A sound to be played
    json:       String,  // Data to be passed through the notification
    autoCancel: Boolean, // Setting this flag and the notification is automatically cancelled when the user clicks it
    ongoing:    Boolean, // Prevent clearing of notification (Android only)
}, callback, scope);
你可以选择

  autoCancel: Boolean, // Setting this flag and the notification is automatically cancelled when the user clicks it
这是工作,但我如何才能删除使用编码

我试着用身份证取消了

function cancelLocalNotificationById(id){
        window.plugin.notification.local.cancel(id, function(){
            alert("cancel callback", id);
        });
    }
}
这将在OnTigger中注册。按id取消将在5秒后运行

function onTrigger(){
 window.plugin.notification.local.ontrigger = function (id, state, json) {
            alert("onTrigger fired");
            alert(id);

                // Cancel alert after 5 seconds...
                timeouts.push(setTimeout(function(){
                    cancelLocalNotificationById(id);
                    alert(id);
                    //alert("cancel reslut"+cancel.status);
                },5000));
}
您应该使用cancel方法通过其id删除通知。从插件文档中:

window.plugin.notification.local.cancel(ID, function () {
    // The notification has been cancelled
}, scope);
其中id仅仅是您要解除的通知的id

正如您提到的,autoCancel是在用户单击通知时自动执行取消操作。如果不是真的,您需要在处理该通知的回调时从Cordova中取消它

更新

事实证明,您正在使用

new Date()
作为添加的通知id,这是原因,因为存在此限制

注意:在Android上,通知id需要是一个字符串,可以 转换成一个数字。如果ID的格式无效,它将被删除 已忽略,但取消通知将失败

newdate()
会产生如下结果

Wed Jan 07 2015 14:16:10 GMT+0200 (FLE Standard Time)

它不能转换成数字。

我认为这里的术语有点混乱。“通知”既用于指示操作系统调度一系列重复消息的指令,也用于引用这些消息的单个实例

autoCancel属性用于在用户点击Android消息栏和窗口以启动应用程序时自动删除通知消息的单个实例。如果将此设置为false,则应用程序图标在这些区域中保持可见,直到用户手动将其删除


回答原始问题:Katzer的插件无法删除与通知实例关联的应用程序图标,而不是autoCancel属性。

我已经这样做了,但通知仍然存在单击删除通知,但按id取消没有t@MohammadFaizanKhan:你能举例说明你的身份证吗使用?@MohammadFaizanKhan:是的,我明白了,但是您最初创建通知的id是什么?换言之,您为window.plugin.notification.local.add传递的参数id值是多少?@MohammadFaizanKhan:如果您真的使用这样编写的
new Date()
,问题就在这里。这就产生了2015年1月7日星期三14:16:10 GMT+0200(FLE标准时间),id不能像Android那样转换为整数。文档中提到了这一点:
注意:在Android上,通知id需要是一个可以转换为数字的字符串。如果ID的格式无效,它将被忽略,但取消通知将失败。