开发者

How to use Javapns to Support Apple's Enhanced Notification Format

Greetings,

I am creating a Java based server to create push notifications for Apple's iOS APNs service. I have found Javapns on google code which seems to provide a simple basic framework to communicate with APNs, and which seems to be fairly wide used.

http://code.google.com/p/javapns/

How开发者_JS百科ever, reading Apple's docs, there is an "enhanced format" for notifications which supports "expiry" i.e. setting a time (well, in seconds) for a notification to expire if it hasn't yet been delivered. I do not see any way to set this using Javapns, and I am unsure how the APNs service handles expiry of notifications if you do not explicitly set it. So,

  1. Does anyone know how to support the enhanced notification format of APNs specifically how to set the expiry?
  2. Does anyone know how Apple handles notification expiry if it isn't explicitly set?
  3. Does anyone have any suggestions that don't require me to start from scratch, as the server is currently functional as is?

Thanks in advance.

Andrew


I have recently made substantial contributions to the JavaPNS project, which lead to the release of JavaPNS 2.0 a few days ago. That version provides full support for the enhanced notification format, including the ability to set your own expiry.

Sylvain


Nice that you found the java library... to bad you didn't read the docs there.

I'll post some of the highlights below:


The existing code uses the 'Simple notification format' which does not return an error EVER.

See docs at: http://developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/CommunicatingWIthAPS/CommunicatingWIthAPS.html

I've tried updating to the 'Enhanced notification format' which is supposed to return an error, but I'm unable to get any errors back from the APNS. (also in the link above)

With the Enhanced format, the connection isn't being dropped immediately after sending data, but I'm not getting anything back from my socket.getInputSocket.read() call.

This issue will have to be tabled until I have more time to troubleshoot.

(Someone else commented) Thanks a lot for looking into it. I got the same result as yours. Maybe it has something to do with Apple Gateway.


So... you could: 1) Build your own 2) Help improve the existing library 3) Try another library like: https://github.com/notnoop/java-apns 4) Do nothing


Enhanced ios push here. To send a notification, you can do it in three steps:

Setup the connection

ApnsService service =
    APNS.newService()
    .withCert("/path/to/certificate.p12", "MyCertPassword")
    .withSandboxDestination()
    .build();

Create and send the message

String payload = APNS.newPayload().alertBody("Can't be simpler than this!").build();
String token = "fedfbcfb....";
service.push(token, payload);

To query the feedback service for inactive devices:

Map<String, Date> inactiveDevices = service.getInactiveDevices();
for (String deviceToken : inactiveDevices.keySet()) {
    Date inactiveAsOf = inactiveDevices.get(deviceToken);
    ...
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜