目录
消息事件
localpush.notify()
提醒服务,本地提醒(非消息推送),应用关闭后无法提醒
使用说明:
使用本方法需要config.xml配置文件中添加cordova-plugin-localpush插件
语法:
- iOS语法:
localpush.notify({
"sendTime" : "",
"sendTitle" :"",
"sendBody" : "",
"icon" : ""
}, null, null);
//添加事件监听
document.addEventListener("localpush.receiveLocalNotification", onlocalReceiveNotification, false);
//回调方法
var onlocalReceiveNotification = function(event) {
alert(event.aps.alert.title);
};
参数:
- sendTime:设置提醒的时间
- sendTitle:设置提醒的标题
- sendBody:设置提醒的内容
- icon: 设置提醒的图片地址
- localpush.receiveLocalNotification:注册事件监听
- onlocalReceiveNotification:事件监听回调方法
示例代码:
localpush.notify({
"sendTime" : "2016-11-03 13:54:30",
"sendTitle" :"提醒标题",
"sendBody" : "您设置了消息提醒事件",
"icon" : "app.png"
}, null, null);
//添加事件监听
document.addEventListener("localpush.receiveLocalNotification", onlocalReceiveNotification, false);
//回调方法
var onlocalReceiveNotification = function(event) {
alert(event.aps.alert.title);
};
Android语法:
localpush.init({},function(){},function (){});
localpush.notify({
"sendTime" : "",
"sendTitle" :"",
"sendBody" : "",
"icon" : ""
}, function(args){
alert("成功点击了本消息"); //用户点击消息后回调
},function(args){
alert("失败回调");
});
localpush.destory({},function(){},function (){});
方法和参数说明:
- init():本地通知初始化方法,一般写在页面加载时。参数如示例中直接都设置为空即可。
- notify():本地通知设置方法,根据需要设置参数。其中,成功回调方法在用户点击消息后回调
- destory():本地通知销毁方法,参数如示例中直接都设置为空即可。
示例代码:
summerready = function () {
localpush.init({},function(){},function (){});
}
function localnotify(){
localpush.notify({
"sendTime" : "2016-11-03 13:54:30",
"sendTitle" :"提醒标题",
"sendBody" : "您设置了消息提醒事件",
"icon" : "app.png"
}, function(args){
//用户点击消息后回调
summer.toast({
"msg":"成功点击了本消息"
});
},function(args){
summer.toast({
"msg":"失败回调"
});
});
}
summer.toast()
提醒服务
语法:
summer.toast({
"msg":"再点击一次退出"
});
参数:
- msg:设置提醒的内容
- duration:持续时间类型;long表示持续时间长,short表示持续时间短
- position:toast显示的位置,top顶部|middle中间|bottom底部,默认middle
示例代码1:
summer.toast({
"msg":"再点击一次退出"
});
示例代码2:
summer.toast({
"msg":"再点击一次退出",
"duration":"short"
});
summer.addEventListener()
注册监听事件,用于指定应用在监听到某种事件情况下需要执行的方法。如:应用从后台恢复到前台时
语法:
summer.addEventListener({
"event": "事件名称",
"handler": "方法名称"
});
参数:
- event:事件名称,目前支持:resume、pause
- pause:应用从前台离开到后台时
- resume:应用从后台恢复到前台时
- handler:事件执行方法名称。
示例:
summer.addEventListener({
"event": "resume",
"handler": "onResume()"
});
function onResume(){
summer.toast({
msg: "应用恢复到前台"
});
}
文档更新时间: 2018-07-03 10:51