Skip to content

Commit

Permalink
Merge branch 'wwdc_features'
Browse files Browse the repository at this point in the history
  • Loading branch information
matzew committed Jul 9, 2014
2 parents 03cac91 + 35e3f65 commit 1f69968
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/main/java/com/notnoop/apns/ApnsServiceBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ public ApnsServiceBuilder asBatched(int waitTimeInSec, int maxWaitTimeInSec) {
/**
* Construct service which will process notification requests in batch.
* After each request batch will wait <code>waitTimeInSec</code> for more request to come
* before executing but not more than <code>maxWaitTimeInSec></code>
* before executing but not more than <code>maxWaitTimeInSec</code>
*
* Each batch creates new connection and close it after finished.
* In case reconnect policy is specified it will be applied by batch processing.
Expand Down
27 changes: 23 additions & 4 deletions src/main/java/com/notnoop/apns/PayloadBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,25 @@ public PayloadBuilder sound(final String sound) {
return this;
}

/**
* Sets the category of the notification for iOS8 notification
* actions. See 13 minutes into "What's new in iOS Notifications"
*
* Passing {@code null} removes the category.
*
* @param category the name of the category supplied to the app
* when receiving the notification
* @return this
*/
public PayloadBuilder category(final String category) {
if (category != null) {
aps.put("category", category);
} else {
aps.remove("category");
}
return this;
}

/**
* Sets the notification badge to be displayed next to the
* application icon.
Expand Down Expand Up @@ -204,7 +223,7 @@ public PayloadBuilder forNewsstand() {
*
* @return this
*/
public PayloadBuilder instantDeliveryOrSlientNofitication() {
public PayloadBuilder instantDeliveryOrSilentNotification() {
root.put("content-available", 1);
return this;
}
Expand Down Expand Up @@ -308,7 +327,7 @@ public int length() {

/**
* Returns true if the payload built so far is larger than
* the size permitted by Apple (which is 256 bytes).
* the size permitted by Apple (which is 2048 bytes).
*
* @return true if the result payload is too long
*/
Expand Down Expand Up @@ -376,7 +395,7 @@ public PayloadBuilder resizeAlertBody(final int payloadLength, final String post

/**
* Shrinks the alert message body so that the resulting payload
* message fits within require Apple specification (256 bytes).
* message fits within require Apple specification (2048 bytes).
*
* This method performs best-effort approach, and its behavior
* is unspecified when handling alerts where the payload
Expand All @@ -391,7 +410,7 @@ public PayloadBuilder shrinkBody() {

/**
* Shrinks the alert message body so that the resulting payload
* message fits within require Apple specification (256 bytes).
* message fits within require Apple specification (2048 bytes).
*
* This method performs best-effort approach, and its behavior
* is unspecified when handling alerts where the payload
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/com/notnoop/apns/ReconnectPolicy.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ public interface ReconnectPolicy {
public enum Provided {
/**
* Only reconnect if absolutely needed, e.g. when the connection is dropped.
* <p/>
* <p>
* Apple recommends using a persistent connection. This improves the latency of sending push notification messages.
* <p/>
* <p>
* The down-side is that once the connection is closed ungracefully (e.g. because Apple server drops it), the library wouldn't
* detect such failure and not warn against the messages sent after the drop before the detection.
*/
Expand All @@ -85,9 +85,9 @@ public ReconnectPolicy newObject() {

/**
* Makes a new connection if the current connection has lasted for more than half an hour.
* <p/>
* <p>
* This is the recommended mode.
* <p/>
* <p>
* This is the sweat-spot in my experiments between dropped connections while minimizing latency.
*/
EVERY_HALF_HOUR {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/notnoop/apns/internal/Utilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public final class Utilities {
public static final String PRODUCTION_FEEDBACK_HOST = "feedback.push.apple.com";
public static final int PRODUCTION_FEEDBACK_PORT = 2196;

public static final int MAX_PAYLOAD_LENGTH = 256;
public static final int MAX_PAYLOAD_LENGTH = 2048;

private Utilities() { throw new AssertionError("Uninstantiable class"); }

Expand Down
24 changes: 12 additions & 12 deletions src/test/java/com/notnoop/apns/PayloadBuilderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ private PayloadBuilder payloadOf(final int l) {
public void detectingLongMessages() {
final String basic = "{\"aps\":{\"alert\":\"\"}}";
final int wrapperOverhead = basic.length();
final int cutoffForAlert = 256 - wrapperOverhead;
final int cutoffForAlert = 2048 - wrapperOverhead;

final PayloadBuilder wayShort = payloadOf(1);
assertFalse(wayShort.isTooLong());
Expand All @@ -321,7 +321,7 @@ public void detectingLongMessages() {
final PayloadBuilder border = payloadOf(cutoffForAlert);
assertFalse(border.isTooLong());
assertTrue(border.length() == wrapperOverhead + cutoffForAlert);
assertTrue(border.length() == 256);
assertTrue(border.length() == 2048);

final PayloadBuilder abitLong = payloadOf(cutoffForAlert + 1);
assertTrue(abitLong.isTooLong());
Expand All @@ -336,8 +336,8 @@ public void detectingLongMessages() {
public void shrinkLongMessages() {
final String basic = "{\"aps\":{\"alert\":\"\"}}";
final int wrapperOverhead = basic.length();
final int cutoffForAlert = 256 - wrapperOverhead;
final int max_length = 256;
final int cutoffForAlert = 2048 - wrapperOverhead;
final int max_length = 2048;

final PayloadBuilder wayShort = payloadOf(1);
wayShort.shrinkBody(); // NOOP
Expand Down Expand Up @@ -368,8 +368,8 @@ public void shrinkLongMessages() {
public void shrinkLongMessagesWithOtherthigns() {
final String basic = "{\"aps\":{\"alert\":\"\"}}";
final int wrapperOverhead = basic.length();
final int cutoffForAlert = 256 - wrapperOverhead;
final int max_length = 256;
final int cutoffForAlert = 2048 - wrapperOverhead;
final int max_length = 2048;

final PayloadBuilder wayShort = payloadOf(1).sound("default");
assertFalse(wayShort.isTooLong());
Expand Down Expand Up @@ -400,7 +400,7 @@ public void shrinkLongMessagesWithOtherthigns() {
public void removeAlertIfSooLong() {
final PayloadBuilder tooLong =
APNS.newPayload()
.customField("test", strOfLen(256))
.customField("test", strOfLen(2048))
.alertBody("what");
tooLong.shrinkBody();
final String payload = tooLong.build();
Expand Down Expand Up @@ -495,9 +495,9 @@ public void utf8EncodingEscaped() {
}

@Test
public void slientPingMessage() {
public void silentPingMessage() {
final PayloadBuilder builder = new PayloadBuilder();
builder.instantDeliveryOrSlientNofitication();
builder.instantDeliveryOrSilentNotification();

final String expected = "{\"aps\":{},\"content-available\":1}";
final String actual = builder.toString();
Expand All @@ -506,10 +506,10 @@ public void slientPingMessage() {
}

@Test
public void slientPingMessageWithCustomKey() {
public void silentPingMessageWithCustomKey() {
final PayloadBuilder builder = new PayloadBuilder();

builder.instantDeliveryOrSlientNofitication();
builder.instantDeliveryOrSilentNotification();
builder.customField("ache1", "what");

final String expected = "{\"aps\":{},\"ache1\":\"what\",\"content-available\":1}";
Expand All @@ -522,7 +522,7 @@ public void slientPingMessageWithCustomKey() {
public void instantMessageWithAlert() {
final PayloadBuilder builder = new PayloadBuilder();
builder.alertBody("test");
builder.instantDeliveryOrSlientNofitication();
builder.instantDeliveryOrSilentNotification();

final String expected = "{\"aps\":{\"alert\":\"test\"},\"content-available\":1}";
final String actual = builder.toString();
Expand Down

0 comments on commit 1f69968

Please sign in to comment.