29,030
社区成员
发帖
与我相关
我的任务
分享
public static void main(String[] args) {
try {
String certificatePath="C:/Users/Administrator/Desktop/ios_distribution.p12" ;
//终端获得的DeviceToken
String deviceToken = "02d01fc03f8392b489ad1c1441fa42056ee7186083abed6c3deb93434538c3f6";
PayLoad payLoad = new PayLoad();
//发送内容
payLoad.addAlert("我的push推送");
//消息推送标记数,小红圈中显示的数字
payLoad.addBadge(100);
//消息声音
payLoad.addSound("default");
PushNotificationManager pushManager = PushNotificationManager.getInstance();
pushManager.addDevice("iPhone", deviceToken);
//连接开发 APNs
String host= "gateway.sandbox.push.apple.com";
//连接产品 APNs
//String host= "gateway.push.apple.com";
int port = 2195;
//push证书导出的p12文件
System.out.println(certificatePath);
//p12文件密码
String certificatePassword= "123456";
pushManager.initializeConnection(host,port, certificatePath,certificatePassword, SSLConnectionHelper.KEYSTORE_TYPE_PKCS12);
//发送推送
Device client = pushManager.getDevice("iPhone");
pushManager.sendNotification(client, payLoad);
//删除deviceToken
pushManager.removeDevice("iPhone");
//停止连接APNS
pushManager.stopConnection();
}
catch (Exception e) {
e.printStackTrace();
}
}