woollllll 2016-07-08 09:44 采纳率: 100%
浏览 6416
已采纳

服务端是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;
    }

}
  • 写回答

3条回答 默认 最新

  • RANDOLPH_SM 2016-07-11 01:40
    关注

    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包
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大