服务端是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;
}
}
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包
大神,有完整的关于IOS的java源代码吗,主要是离线消息推送
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);
List<String> appIds = new ArrayList<String>();
appIds.add(appId);
// 定义"AppMessage"类型消息对象,设置消息内容模板、发送的目标App列表、是否支持离线发送、以及离线消息有效期(单位毫秒)
AppMessage message = new AppMessage();
TransmissionTemplate transmissionTemplate = getTransmissionTemplate();
message.setData(transmissionTemplate);
message.setAppIdList(appIds);
message.setOffline(true);
message.setOfflineExpireTime(1000 * 600);
// 厂商下发策略;1: 个推通道优先,在线经个推通道下发,离线经厂商下发(默认);2: 在离线只经厂商下发;3: 在离线只经个推通道下发;4: 优先经厂商下发,失败后经个推通道下发;
message.setStrategyJson("{\"ios\":2}");
IPushResult ret = push.pushMessageToApp(message);
System.out.println(ret.getResponse().toString());
}
/**
* 透传消息模版,透传消息是指消息传递到客户端只有消息内容,展现形式由客户端自行定义。客户端可自定义通知的展现形式,也可自定义通知到达之后的动作,或者不做任何展现。
* @return
*/
public static TransmissionTemplate getTransmissionTemplate() {
TransmissionTemplate template = new TransmissionTemplate();
// 设置APPID与APPKEY
template.setAppId(APPID);
template.setAppkey(APPKEY);
//透传消息设置,1为强制启动应用,客户端接收到消息后就会立即启动应用;2为等待应用启动
template.setTransmissionType(2);
template.setTransmissionContent("透传内容"); //透传内容
template.setAPNInfo(getAPNPayload()); //ios消息推送
return template;
}
private static APNPayload getAPNPayload() {
APNPayload payload = new APNPayload();
//在已有数字基础上加1显示,设置为-1时,在已有数字上减1显示,设置为数字时,显示指定数字
payload.setAutoBadge("+1");
payload.setContentAvailable(1);
//ios 12.0 以上可以使用 Dictionary 类型的 sound
payload.setSound("default");
payload.setCategory("$由客户端定义");
payload.addCustomMsg("由客户自定义消息key", "由客户自定义消息value");
//简单模式APNPayload.SimpleMsg
payload.setAlertMsg(new APNPayload.SimpleAlertMsg("hello_123"));
//设置语音播报类型,int类型,0.不可用 1.播放body 2.播放自定义文本
payload.setVoicePlayType(2);
//设置语音播报内容,String类型,非必须参数,用户自定义播放内容,仅在voicePlayMessage=2时生效
//注:当"定义类型"=2, "定义内容"为空时则忽略不播放
payload.setVoicePlayMessage("定义内容");
// 添加多媒体资源
payload.addMultiMedia(new MultiMedia()
.setResType(MultiMedia.MediaType.pic)
.setResUrl("资源文件地址")
.setOnlyWifi(true));
return payload;
}
}
厂商策略指定 message.setStrategyJson("{\"ios\":2}");
需要Java-sdkb版本4.1.1.0及以上;