JAVA APNs Apple Push __java

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.