调用cordova相关插件进行消息推送(通知栏提醒、响铃、震动)

原文: 调用cordova相关插件进行消息推送(通知栏提醒、响铃、震动)

版权声明:本文为博主原创文章,转载须注明出处,博客地址:https://blog.csdn.net/wx13227855087 https://blog.csdn.net/wx13227855087/article/details/85003061

最近项目中需要对自己软件的备忘录进行消息推送,从而提醒用户。闲话就不多说了,将自己用到的插件以及使用方法简单分享一下,有什么做的不好的地方或者好的建议欢迎随时提出,谢谢!


一、本地消息通知插件,这里使用cordova-plugin-local-notifications-appstr

添加插件:cordova plugin add cordova-plugin-local-notifications-appstr

提示:插件的使用需在终端上打开锁屏、通知栏和状态栏权限

(1)该插件创建对象cordova.plugins.notification.local,并在触发deviceready之后访问。

调用示例:

cordova.plugins.notification.local.schedule({

    title: 'My first notification',

    text: 'Thats pretty easy...',

    foreground: true

});

效果如下图:

(2)该插件允许同时调度多个通知。

cordova.plugins.notification.local.schedule([

    { id: 1, title: 'My first notification' },

    { id: 2, title: 'My first notification' }

]);

(3)配置项

Property Property Property Property Property Property Property Property
id data timeoutAfter summary led clock channel actions
text icon attachments smallIcon color defaults launch groupSummary
title silent progressBar sticky vibrate priority mediaSession foreground
sound trigger group autoClear lockscreen number badge wakeup

二、响铃插件cordova-plugin-dialogs

添加插件:cordova plugin add cordova-plugin-dialogs

包含的方法:

            navigator.notification.alert  //警告框

            navigator.notification.confirm  //确认框

            navigator.notification.prompt  //提示框

            navigator.notification.beep  //提示音

调用示例:navigator.notification.beep方法使用

navigator.notification.beep(numbers);

numbers为数字,代表提示次数。

三、震动插件cordova-plugin-vibration

添加插件:cordova plugin add cordova-plugin-vibration

调用:

navigator.vibrate(2000);    //震动2秒

猜你喜欢

转载自www.cnblogs.com/lonelyxmas/p/10232955.html