目录

消息事件

localpush.notify()

提醒服务,本地提醒(非消息推送),应用关闭后无法提醒

使用说明:
使用本方法需要config.xml配置文件中添加cordova-plugin-localpush插件

语法:

  • iOS语法:
    1. localpush.notify({
    2. "sendTime" : "",
    3. "sendTitle" :"",
    4. "sendBody" : "",
    5. "icon" : ""
    6. }, null, null);
    7. //添加事件监听
    8. document.addEventListener("localpush.receiveLocalNotification", onlocalReceiveNotification, false);
    9. //回调方法
    10. var onlocalReceiveNotification = function(event) {
    11. alert(event.aps.alert.title);
    12. };

参数:

  • sendTime:设置提醒的时间
  • sendTitle:设置提醒的标题
  • sendBody:设置提醒的内容
  • icon: 设置提醒的图片地址
  • localpush.receiveLocalNotification:注册事件监听
  • onlocalReceiveNotification:事件监听回调方法

示例代码:

  1. localpush.notify({
  2. "sendTime" : "2016-11-03 13:54:30",
  3. "sendTitle" :"提醒标题",
  4. "sendBody" : "您设置了消息提醒事件",
  5. "icon" : "app.png"
  6. }, null, null);
  7. //添加事件监听
  8. document.addEventListener("localpush.receiveLocalNotification", onlocalReceiveNotification, false);
  9. //回调方法
  10. var onlocalReceiveNotification = function(event) {
  11. alert(event.aps.alert.title);
  12. };

Android语法:

  1. localpush.init({},function(){},function (){});
  2. localpush.notify({
  3. "sendTime" : "",
  4. "sendTitle" :"",
  5. "sendBody" : "",
  6. "icon" : ""
  7. }, function(args){
  8. alert("成功点击了本消息"); //用户点击消息后回调
  9. },function(args){
  10. alert("失败回调");
  11. });
  12. localpush.destory({},function(){},function (){});

方法和参数说明:

  • init():本地通知初始化方法,一般写在页面加载时。参数如示例中直接都设置为空即可。
  • notify():本地通知设置方法,根据需要设置参数。其中,成功回调方法在用户点击消息后回调
  • destory():本地通知销毁方法,参数如示例中直接都设置为空即可。

示例代码:

  1. summerready = function () {
  2. localpush.init({},function(){},function (){});
  3. }
  4. function localnotify(){
  5. localpush.notify({
  6. "sendTime" : "2016-11-03 13:54:30",
  7. "sendTitle" :"提醒标题",
  8. "sendBody" : "您设置了消息提醒事件",
  9. "icon" : "app.png"
  10. }, function(args){
  11. //用户点击消息后回调
  12. summer.toast({
  13. "msg":"成功点击了本消息"
  14. });
  15. },function(args){
  16. summer.toast({
  17. "msg":"失败回调"
  18. });
  19. });
  20. }

用例github下载地

summer.toast()

提醒服务

语法:

  1. summer.toast({
  2. "msg":"再点击一次退出"
  3. });

参数:

  • msg:设置提醒的内容
  • duration:持续时间类型;long表示持续时间长,short表示持续时间短
  • position:toast显示的位置,top顶部|middle中间|bottom底部,默认middle

示例代码1:

  1. summer.toast({
  2. "msg":"再点击一次退出"
  3. });

示例代码2:

  1. summer.toast({
  2. "msg":"再点击一次退出",
  3. "duration":"short"
  4. });

用例github下载地

summer.addEventListener()

注册监听事件,用于指定应用在监听到某种事件情况下需要执行的方法。如:应用从后台恢复到前台时
语法:

  1. summer.addEventListener({
  2. "event": "事件名称",
  3. "handler": "方法名称"
  4. });

参数:

  • event:事件名称,目前支持:resume、pause
    • pause:应用从前台离开到后台时
    • resume:应用从后台恢复到前台时
  • handler:事件执行方法名称。

示例:

  1. summer.addEventListener({
  2. "event": "resume",
  3. "handler": "onResume()"
  4. });
  5. function onResume(){
  6. summer.toast({
  7. msg: "应用恢复到前台"
  8. });
  9. }
文档更新时间: 2018-07-03 10:51