前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >极光推送

极光推送

作者头像
阿超
发布2024-01-24 08:20:35
1320
发布2024-01-24 08:20:35
举报
文章被收录于专栏:快乐阿超快乐阿超

忍耐能化怯懦为力量,焦急却化力量为懦弱。——科尔顿

代码如下:

代码语言:javascript
复制
JPushClient jpushClient = new JPushClient(jPushMasterSecret, jPushAppKey, null, ClientConfig.getInstance());

// For push, all you need do is to build PushPayload object.
var payload = PushPayload.newBuilder()
        // 推送平台设置
        .setPlatform(Platform.ios())
        // 推送设备指定
        .setAudience(Audience.all())
        // 通知内容体,是被推送到客户端的内容。与 message 一起二者必须有其一,可以二者并存。
        .setNotification(Notification.newBuilder()
                .addPlatformNotification(IosNotification.newBuilder()
                        .setAlert(dto.getMsg())
                        .setBadge(0)
                        .setSound("default")
                        .build())
                .build())
        // 应用内消息,又称作:自定义消息,透传消息。
        // 此部分内容不会展示到通知栏上,JPush SDK 收到消息内容后透传给 App,需要 App 自行处理。
        // iOS 在推送应用内消息通道(非 APNS)获取此部分内容,需 App 处于前台。
        .setMessage(Message.content(dto.getContent()))
        .setOptions(Options.newBuilder()
                .setApnsProduction(true)
                .build())
        .build();

try {
    PushResult result = jpushClient.sendPush(payload);
    sink.success(result);
    LOG.info("Got result - " + result);

} catch (APIConnectionException e) {
    // Connection error, should retry later
    LOG.error("Connection error, should retry later", e);
    sink.error(e);
} catch (APIRequestException e) {
    // Should review the error, and fix the request
    LOG.error("Should review the error, and fix the request", e);
    LOG.info("HTTP Status: " + e.getStatus());
    LOG.info("Error Code: " + e.getErrorCode());
    LOG.info("Error Message: " + e.getErrorMessage());
    sink.error(e);
}

代码仓库:

https://github.com/jpush/jpush-api-java-client

文档如下:

创建推送 API - 极光文档

本文参与?腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2024-01-23,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客?前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与?腾讯云自媒体分享计划? ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
http://www.vxiaotou.com