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

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


一、本地消息通知插件,这里使用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)配置项

PropertyPropertyPropertyPropertyPropertyPropertyPropertyProperty
iddatatimeoutAftersummaryledclockchannelactions
texticonattachmentssmallIconcolordefaultslaunchgroupSummary
titlesilentprogressBarstickyvibrateprioritymediaSessionforeground
soundtriggergroupautoClearlockscreennumberbadgewakeup

二、响铃插件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秒


版权声明:本文为wx13227855087原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。