之前发布了一次通过个推推送消息的文章 点此查看文章
这次则记录一下用unipush进行推送的用法,unipush和个推本质没有什么区别,
unipush相当于个推的进阶版,对于服务端,客服端的业务大致没什么影响;值得注意的时unipush多了一些参数配置信息(服务端;变化不多);对于客服端应该是没有变化的(未做过多关注)。
这次主要分享下推送模板:透传模板和通知模板的区别:
通知模板:自定义通知栏样式,通知栏内容(支持安卓在线离线;不支持苹果在线)
透传模板:仅用来传递数据,不支持通知栏设置。
若是想兼容安卓和ios;那就需要使用透传模板(或者花钱开通vip,这样通知模板也是支持ios在线的)。使用透传模板的话;则需要客户端去做通知栏弹出的处理。
通知模板:NotificationTemplate 样式设置如下:这里是安卓设置
苹果离线通知栏设置如下:给 APNPayload 赋值
完整代码如下:
private static void touClientNotifyMsg(AppBindRecord bind, IBatch batch,String body,String title) throws Exception {
SingleMessage message = new SingleMessage();
NotificationTemplate template = new NotificationTemplate();
// 设置APPID与APPKEY
template.setAppId(UniAppUtil.ItnsAppId);
template.setAppkey(UniAppUtil.ItnsAppKey);
Style0 style = new Style0();
style.setTitle(title);
style.setText(body);
style.setLogoUrl("");
style.setRing(true);
style.setVibrate(true);
style.setClearable(true);
style.setChannel("");
style.setChannelName("");
style.setChannelLevel(3);
template.setStyle(style);
APNPayload apnpayload = new APNPayload();
apnpayload.setSound("default");
apnpayload.setAlertMsg(getDictionaryAlertMsg(title,body));
template.setAPNInfo(apnpayload);
message.setData(template);
message.setOffline(true);
message.setPushNetWorkType(0);
message.setOfflineExpireTime(360 * 1000);
// 厂商通道下发策略
message.setStrategyJson("{\"default\":1,\"ios\":4,\"st\":1}");
Target target = new Target();
target.setAppId(UniAppUtil.ItnsAppId);
target.setClientId(bind.getDeviceId());
batch.add(message, target);
}
/**
* 苹果通知样式
* @return
*/
private static APNPayload.DictionaryAlertMsg getDictionaryAlertMsg(String title,String body){
APNPayload.DictionaryAlertMsg alertMsg = new APNPayload.DictionaryAlertMsg();
alertMsg.setTitle(title);
alertMsg.setBody(body);
alertMsg.setActionLocKey("ActionLockey");
//显示关闭和查看两个按钮的消息;
alertMsg.setLocKey("LocKey");
alertMsg.addLocArg("loc-args");
alertMsg.setLaunchImage("launch-image");
// iOS8.2以上版本支持
alertMsg.setTitleLocKey("TitleLocKey");
alertMsg.addTitleLocArg("TitleLocArg");
return alertMsg;
}