unipush推送使用的注意要点

之前发布了一次通过个推推送消息的文章 点此查看文章

这次则记录一下用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;
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

博客胡

你的鼓励是我最大的动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值