Compare with Javapns - notnoop/java-apns GitHub Wiki

I have built this library after much frustration with the more popular Javapns library is a popular library for sending Apple Notification. The javapns library has many limitations and encourage writing bad code. The documentations are dismal and not tests are provided!

Client Code cleanliness

First let’s compare how the client code looks and examine it. I’m using the provided examples from the javapns documentation

1. Simple message notification:

With javapns:

PayLoad simplePayLoad = new PayLoad();
simplePayLoad.addAlert("My alert message");
simplePayLoad.addBadge(45);
simplePayLoad.addSound("default");
Device client = PushNotificationManager.getInstance().getDevice("my_iPhone");
PushNotificationManager.getInstance().initializeConnection("gateway.sandbox.push.apple.com", 2195, "C:/temp/myCertificate.p12", "p@ssw0rd", SSLConnectionHelper.KEYSTORE_TYPE_PKCS12);
PushNotificationManager.getInstance().sendNotification(client, simplePayLoad);

With java-apns:

String simplePayload = APNS.newPayload()
    .alert("My alert message").badge(45).sound("default").build();

String client = myDatabase.get("my_iphone");

ApnsService service = APNS.newService()
    .withCert("C:/temp/myCertificate.p12", "p@ssw0rd")
    .withSandboxDestination()
    .build();

service.push(client, simplePayload);

2. Sending complex notification

// Or create a complex PayLoad with a custom alert
PayLoad complexPayLoad = new PayLoad();
PayLoadCustomAlert customAlert = new PayLoadCustomAlert();
// You can use addBody to add simple message, but we'll use
// a more complex alert message so let's comment it
// customAlert.addBody("My alert message");
customAlert.addActionLocKey("Open App");
customAlert.addLocKey("javapns rocks %@ %@%@");
ArrayList parameters = new ArrayList();
parameters.add("Test1");
parameters.add("Test");
parameters.add(2);
customAlert.addLocArgs(parameters);
complexPayLoad.addCustomAlert(customAlert);
complexPayLoad.addBadge(45);
complexPayLoad.addSound("default");
complexPayLoad.addCustomDictionary("acme", "foo");
complexPayLoad.addCustomDictionary("acme2", 42);
ArrayList values = new ArrayList();
values.add("value1");
values.add(2);
complexPayLoad.addCustomDictionary("acme3", values);
Device client = PushNotificationManager.getInstance().getDevice("my_iPhone");
PushNotificationManager.getInstance().initializeConnection("gateway.sandbox.push.apple.com", 2195, "C:/temp/myCertificate.p12", "p@ssw0rd", SSLConnectionHelper.KEYSTORE_TYPE_PKCS12);
PushNotificationManager.getInstance().sendNotification(client, complexPayLoad);

With java-apns:

String complex = APNS.newPayload()
    .actionKey("Open App")
    .localizedKey("javapns rocks %@ %@%@")
    .localizedArguments("Test1", "Test", "2")
    .badge(45).sound("default")
    .customField("acme", "foo")
    .customField("acme", 42)
    .customField("acme3", Arrays.<Object>asList("value1", 2))
    .build();

String client = myDatabase.get("my_iphone");

ApnsService service = APNS.newService()
    .withCert("c:/temp/myCertificate.p12", "p@ssw0rd")
    .withSandboxDestination()
    .build();
service.push(client, complex);

Should I even try to compare?

⚠️ **GitHub.com Fallback** ⚠️