Recently in doing Apple push, found a better open source project, the Chinese wrote
Download the address: Https://github.com/RamosLi/dbay-apns-for-java
The calling code is as follows:
Import Java.io.InputStream;
Import java.util.List;
Import Com.dbay.apns4j.IApnsService;
Import Com.dbay.apns4j.impl.ApnsServiceImpl;
Import Com.dbay.apns4j.model.ApnsConfig;
Import Com.dbay.apns4j.model.Feedback;
Import Com.dbay.apns4j.model.Payload;
/** * @author RAMOSLI * */public class Apns4jdemo {private static Iapnsservice apnsservice;
private static Iapnsservice Getapnsservice () {if (Apnsservice = null) {apnsconfig config = new Apnsconfig ();
InputStream is = Apns4jDemo.class.getClassLoader (). getResourceAsStream ("CERTIFICATE.P12");
Config.setkeystore (IS);
Config.setdevenv (FALSE);
Config.setpassword ("123123");
Config.setpoolsize (5);
Apnsservice = apnsserviceimpl.createinstance (config);
return apnsservice;
public static void Main (string[] args) {Iapnsservice service = Getapnsservice ();
Send notification String token = "94c4764e4645f42a7b2052692c8b5b41f9d5c925876e11fec5721e9045ee4e5b"; Payload Payload = new Payload ();
Payload.setalert ("How to Are You?"); The If is absent, the badge isn't changed.
To remove the badge, set the value of the ' to 0 Payload.setbadge (1);
Set sound null, the music won ' t be played//Payload.setsound (NULL);
Payload.setsound ("Msg.mp3");
Payload.addparam ("UID", 123456);
Payload.addparam ("type", 12);
Service.sendnotification (token, payload);
Payload, use loc string payload payload2 = new payload ();
Payload2.setbadge (1);
Payload2.setalertlockey ("Game_play_request_format");
Payload2.setalertlocargs (New string[]{"Jenna", "Frank"});
Service.sendnotification (token, payload2);
Get feedback list<feedback> List = Service.getfeedbacks (); if (list!= null && list.size () > 0) {for (Feedback feedback:list) {System.out.println (feedback.getd
Ate () + "" + Feedback.gettoken ());
} try {//Sleep 5s.
Thread.Sleep (5000);
catch (Exception e) {e.printstacktrace (); }
// It ' s a good habit to shutdown what your never use Service.shutdown ();
System.exit (0); }
}
Contains the push function, Apple's feedback function, is very practical and convenient.
For the source code, I organized into a project, download the address for: http://download.csdn.net/detail/linyu19872008/6934361