JAVA APNS蘋果推送__JAVA

來源:互聯網
上載者:User

最近在做蘋果推送,找到了一個比較好的開源項目,國人寫的

下載地址為:https://github.com/RamosLi/dbay-apns-for-java

調用代碼如下:

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 notificationString token = "94c4764e4645f42a7b2052692c8b5b41f9d5c925876e11fec5721e9045ee4e5b";Payload payload = new Payload();payload.setAlert("How are you?");// If this property is absent, the badge is not changed. To remove the badge, set the value of this property to 0payload.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 stringPayload payload2 = new Payload();payload2.setBadge(1);payload2.setAlertLocKey("GAME_PLAY_REQUEST_FORMAT");payload2.setAlertLocArgs(new String[]{"Jenna", "Frank"});service.sendNotification(token, payload2);// get feedbackList<Feedback> list = service.getFeedbacks();if (list != null && list.size() > 0) {for (Feedback feedback : list) {System.out.println(feedback.getDate() + " " + feedback.getToken());}}try {// sleep 5s.Thread.sleep(5000);} catch (Exception e) {e.printStackTrace();}// It's a good habit to shutdown what you never useservice.shutdown();//System.exit(0);}}

包含推送功能、蘋果的feedback功能,很是實用方便。

對於源碼,我整理成了工程,下載地址為:http://download.csdn.net/detail/linyu19872008/6934361

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.