---
title: "【最好用的】Java APNS开源库apns4j-1.1.1发布"
author: "冲杯茶喝"
date: "2016-10-10T22:39:11Z"
tags: []
categories: ["移动开发"]
slug: "java-apns-apns4j-1-1-1"
draft: false
lastmod: "2016-10-10T22:39:11Z"
id: 2329632
url: "https://teaey.iteye.com/blog/2329632"
---

开源地址：[https://github.com/teaey/apns4j](https://github.com/teaey/apns4j)

# 【最好用的】Java APNS开源库apns4j-1.1.1发布

- 提升API的易用性，移除繁杂的初始化逻辑，入口集中到cn.teaey.apns4j.Apns4j
- 提供简单的异步服务
- 增加ios7以上静默推送设置（content-available）
- sendAndFlush -&gt; send 或许开始就是个错误！
- 减少builder模式，能够更好的与spring等框架做集成
- groupId调整：cn.teaey.apns4j

```
<dependency>
    <groupId>cn.teaey.apns4j</groupId>
    <artifactId>apns4j</artifactId>
    <version>1.1.1</version>
</dependency>
```

```
//Step 1
ApnsChannelFactory apnsChannelFactory = Apns4j.newChannelFactoryBuilder()
.keyStoreMeta("${path to your keystore}")
.keyStorePwd("${keystore password}")
.build();

//Setp 2
ApnsChannel apnsChannel = apnsChannelFactory.newChannel();

//Step 3 create & init notify payload
ApnsPayload apnsPayload = Apns4j.newPayload()
        .alertTitle("Title")
        .alertBody("Pushed by apns4j")
        .sound("default");

//Step 4 send via channel
apnsChannel.send("${target device token}", apnsPayload);

//Step 5 in the end, apnsChannel can be Recycle and Reuse 
apnsChannel.close();
```

`from iteye`

开源地址：[https://github.com/teaey/apns4j](https://github.com/teaey/apns4j)

联系作者：   
masfay@me.com   
github：[http://github.com/teaey](http://github.com/teaey)