服务端是java,使用个推给IOS推送消息,IOS通知栏能收到那种,求参考代码

服务端是java,使用个推给IOS推送消息,IOS通知栏能收到那种,求参考代码
我是参考个推官网的例子,IOS接收不到

 public class Test {

    //定义常量, appId、appKey、masterSecret 采用本文档 "第二步 获取访问凭证 "中获得的应用配置
    private static String appId = "";
    private static String appKey = "";
    private static String masterSecret = "";
    private static String url = "http://sdk.open.api.igexin.com/apiex.htm";

    public static void main(String[] args) throws IOException {

        IGtPush push = new IGtPush(url, appKey, masterSecret);

        // 定义"点击链接打开通知模板",并设置标题、内容、链接
        LinkTemplate template = new LinkTemplate();
        template.setAppId(appId);
        template.setAppkey(appKey);
        template.setTitle("欢迎使用个推!!!!!!!!!!!!!");
        template.setText("这是一条推送消息~!!!!!!!!!!");
        template.setUrl("http://getui.com");

        List<String> appIds = new ArrayList<String>();
        appIds.add(appId);

        // 定义"AppMessage"类型消息对象,设置消息内容模板、发送的目标App列表、是否支持离线发送、以及离线消息有效期(单位毫秒)
        AppMessage message = new AppMessage();
        TransmissionTemplate transmissionTemplate = getTemplate();
        message.setData(transmissionTemplate);
        message.setAppIdList(appIds);
        message.setOffline(true);
        message.setOfflineExpireTime(1000 * 600);

    //    notificationTemplateDemo(appId, appKey);

        IPushResult ret = push.pushMessageToApp(message);
        System.out.println(ret.getResponse().toString());
    }

    public static TransmissionTemplate getTemplate() {
        TransmissionTemplate template = new TransmissionTemplate();
        template.setAppId(appId);
        template.setAppkey(appKey);
        template.setTransmissionContent("透传内容");
        template.setTransmissionType(2);
        APNPayload payload = new APNPayload();
        payload.setBadge(1);
        payload.setContentAvailable(1);
        payload.setSound("default");
        payload.setCategory("$由客户端定义");
        //简单模式APNPayload.SimpleMsg 
        payload.setAlertMsg(new APNPayload.SimpleAlertMsg("hello"));
        //字典模式使用下者
      //  payload.setAlertMsg(getDictionaryAlertMsg());
      //  template.setAPNInfo(payload);
        return template;
    }
    private static APNPayload.DictionaryAlertMsg getDictionaryAlertMsg(){
        APNPayload.DictionaryAlertMsg alertMsg = new APNPayload.DictionaryAlertMsg();
        alertMsg.setBody("body");
        alertMsg.setActionLocKey("ActionLockey");
        alertMsg.setLocKey("LocKey");
        alertMsg.addLocArg("loc-args");
        alertMsg.setLaunchImage("launch-image");
        // IOS8.2以上版本支持
        alertMsg.setTitle("Title");
        alertMsg.setTitleLocKey("TitleLocKey");
        alertMsg.addTitleLocArg("TitleLocArg");
        return alertMsg;
    }

}

2个回答

public String sendMsgIos(AniuMessage aniuMessage) {
PushedNotifications pushedNotification = null;
AniuPushClient aniuPushClient = dao.getByClientId(aniuMessage.getReceiverAniuUid());
String certificatePath = "/data/push.p12"; // 前面生成的用于JAVA后台连接APNS服务的*.p12文件位置
String certificatePassword = "123456"; // "tlstjddlf";//p12文件密码。
String success = null;
try {
LOGGER.info("+++++++++++++++开始推送++++++++++++++++++++");
pushedNotification = Push.alert(aniuMessage.getContent(),certificatePath, certificatePassword, false,aniuPushClient.getClientId());
for (PushedNotification pushed : pushedNotification) {

            if (pushed.isSuccessful()) {
                success = pushed.getDevice().getToken();
            }
        }
    } catch (CommunicationException e) {
        e.printStackTrace();
    } catch (KeystoreException e) {
        e.printStackTrace();
    }

    return success;
}


搞定,但是要自己去找jar包
tiange365881557
tiange365881557 大神,请上jar包啊
一年多之前 回复
u013508530
黑马过林V 回复woollllll: 楼主你好,遇到同样问题,能否告知下解决方案!
2 年多之前 回复
zhaozjc112
woollllll 谢谢帮助~
3 年多之前 回复

大神,有完整的关于IOS的java源代码吗,主要是离线消息推送

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问