EzDevInfo.com

java-apns

Java Apple Push Notification Service Provider Java Apple Push Notification Service Library - About

APNS production certificate not working

i am new bie in push notification and trying to apns push notification but it not working.

my code is

    ApnsService service = APNS.newService()
            .withCert(apns_keystore, apns_keystore_password)
            .withProductionDestination().build();
    String payload = APNS.newPayload().badge((int) badge)
            .alertBody(body).sound("chime").actionKey(from).build();
    service.push(token, payload);

please help me


Source: (StackOverflow)

APNS strange behavior

Today I've send a push notification to my users through my api with text "Hey, check out new store", but users get from 4 to 10 notifications like:

Hey,
Hey,2
Hey, c
Hey, checkout

And after this they got full message. I'm using Java apns to send notifications, and the code is pretty straightforward, so there is no mistake there. How could this be? Can it be a browser problem, which triggered multiple API calls?


Source: (StackOverflow)

Advertisements

APNS not working overnight

I used to send notifications to iOS phones through my server.

My APNS certificate hasn't changed since December 2014, and is still valid.

However, I get, since yesterday, this error when the server tries to send any APNS notifications:

Caused by: javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake
Caused by: java.io.EOFException: SSL peer shut down incorrectly

What could be the reason? Since I strictly didn't change my backend (no delivery) and it worked yesterday...

May it be a temporary bug regarding APNS server?


Source: (StackOverflow)

What's the correct format for Java APNS certificate?

I'm using Java APNS (com.notnoop.apns, v0.2.3) to send Push Notifications to my iOS app. I'm creating the APNS service with the following lines:

private ApnsService createApnsService() throws IOException {
        ApnsServiceBuilder serviceBuilder = APNS.newService().withCert(certResource.getInputStream(), certPassword);
        serviceBuilder.withSandboxDestination();
        return serviceBuilder.build();
}

And receive the following exception:

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is com.notnoop.exceptions.NetworkIOException: javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure\n\tat org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:948)\n\tat org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:838)\n\tat javax.servlet.http.HttpServlet.service(HttpServlet.java:647)\n\tat org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812)\n\tat javax.servlet.http.HttpServlet.service(HttpServlet.java:728)\n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)...    <<...the stacktrace is much longer, but I've cut it of here, since nobody would read it anyway...>>

I'm guessing that my P12 certificate is incorrect. (I've also tried PEM certificate already.) At the moment I've created the P12 certificate at this way and then applied a password:

Screenshot of Keychain.app


What's the correct way to create the certificate which is compatible with Java APNS?


Source: (StackOverflow)

Bug in the Amazon SNS Apple Push Notification Tutorial (Null Pointer Exception)

My goal end goal is to send push notifications to an iOS app via SNS. I am stepping through this tutorial: http://docs.aws.amazon.com/sns/latest/dg/mobile-push-apns.html.

I have added in my AWS credentials, and added in the corresponding apns credentials for my development key, certificate, private key, and a current push token for my app. When I run the tutorial I get:

Exception in thread "main" java.lang.NullPointerException
at com.amazonaws.sns.samples.tools.AmazonSNSClientWrapper.getValidNotificationAttributes(AmazonSNSClientWrapper.java:162)
at com.amazonaws.sns.samples.tools.AmazonSNSClientWrapper.publish(AmazonSNSClientWrapper.java:80)
at com.amazonaws.sns.samples.tools.AmazonSNSClientWrapper.demoNotification(AmazonSNSClientWrapper.java:131)
at com.amazonaws.sns.samples.mobilepush.SNSMobilePush.demoAppleSandboxAppNotification(SNSMobilePush.java:438)
at com.amazonaws.sns.samples.mobilepush.SNSMobilePush.main(SNSMobilePush.java:68)

At the top of SNSMobilePush.java there is a Map called attributesMap. It originally has values set to null for keys Platform.APNS and Platform.APNS_SANDBOX. These values never get changed anywhere during the code and are responsible for causing the null pointer exception. The tutorial does not indicate to change these values.

I did not do anything above or beyond the tutorial instructions.

I know that my credentials are correct as I did send a message to my iOS app using these same credentials via Amazon Management Console.

Can anyone indicated

  • if the tutorial is incomplete
  • what the values associated with Platform.APNS_SANDBOX should be in order to get this working
  • any hint to help me trouble shoot this

update I added in a null check to getValidNotificationAttributes() and now I am able to send push notifications using sns and apns using this tutorial.


Source: (StackOverflow)

Java TLS socket : No trusted certificate found

Let me explain quickly what I'm trying to do. I'm trying to build my own Apple's Push Notification service in java (for testing purposes). This service works thanks to TLS socket.

I have a java client to create a TLS socket to send push notifications to the APNs. I changed the host url to redirect the socket to localhost:2195. Now I'm trying to write a java socket server to get the notification request.

However, I get an exception during the handshake and can't find how to fix it.

Note : I'm using the same certificate on both sides, it's a standard .p12 file that works to send push notifications to the APNs.

Here is the client (simplified) :

KeyStore ks = KeyStore.getInstance("PKCS12");
ks.load(new FileInputStream(certificatePath), password.toCharArray());

KeyManagerFactory kmf = KeyManagerFactory.getInstance("sunx509");
kmf.init(ks, password.toCharArray());

TrustManagerFactory tmf = TrustManagerFactory.getInstance("sunx509"); 
tmf.init((KeyStore)null);

SSLContext sc = SSLContext.getInstance("TLS"); 
sc.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null); 

SSLSocketFactory ssf = sc.getSocketFactory(); 
SSLSocket socket = (SSLSocket) ssf.createSocket(InetAddress.getLocalHost(), 2195);
socket.startHandshake();

Here is the server :

KeyStore ks = KeyStore.getInstance("PKCS12");
ks.load(new FileInputStream(certificatePath), password.toCharArray());

KeyManagerFactory kmf = KeyManagerFactory.getInstance("sunx509");
kmf.init(ks, password.toCharArray());

SSLContext context = SSLContext.getInstance("TLS");
context.init(kmf.getKeyManagers(), null, null);

SSLServerSocketFactory ssf = context.getServerSocketFactory();
serverSocket = (SSLServerSocket) ssf.createServerSocket(2195);

And here is the exception :

javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: No trusted certificate found

I guess the client isn't trusting the server's certificate. I tryed to set the client's TrustManager to accept the server's p12 and it worked, however I need this to work without editing the client (since it's working that way with the real APNs).

What kind of certificate needs the server to be trusted by the client ?

Thanks in advance.


Source: (StackOverflow)

iOS Notification - How to manage two app IDs with one P12 file

I have a notification project that is built for iPhone and iPad. So I have 2 app IDs = 2 applications on the Apple Store.

If I understand the official Apple Guide Lines (https://developer.apple.com/library/ios/documentation/IDEs/Conceptual/AppDistributionGuide/ConfiguringPushNotifications/ConfiguringPushNotifications.html), I have to create a Push Notification Certificate for a specific App ID. So 2 certificates for notification feature will be created at the end due to the two App IDs I have.

On my server application, I have to manage a .p12 file to send notifications. It works well when I have 1 APNs certificate inside (for example the one that concerns my iPhone app). When I have a .p12 file that contains the 2 APNs certificates (iPhone + iPad), I can't send notifications from server side ! Error is "Failed to deliver notification with error code 8". I'm using Sandbox gateway as I'm using a DEV certificate.

How to manage the 2 app in one .p12 file ? Is it possible ? I'm using https://github.com/notnoop/java-apns library.

Thank you for your time,


Source: (StackOverflow)

Unable to send push notification to iPhone

I am sending push-notification to i-phone using Java APNs. Am able to send notification to one app but am not able to send notification to other apps. For first app (Successful sending push notification) am using

String json1= "{\"aps\":{\"alert\":\"Testing.. (3)\",\"badge\":1,\"sound\":\"default\"}}";
PushNotificationPayload payLoad = null;
        try {
            payLoad = PushNotificationPayload.fromJSON(json1);
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        Push.payload(payLoad , "/home/owner/Downloads/v.p12", null, false, "97884fe9ffeb6f5....");

and for other app (unsuccessful) am using the same

 String json1= "{\"aps\":{\"alert\":\"Testing.. (3)\",\"badge\":1,\"sound\":\"default\"}}";
    PushNotificationPayload payLoad = null;
            try {
                payLoad = PushNotificationPayload.fromJSON(json1);
            } catch (JSONException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

            Push.payload(payLoad , "/home/owner/Downloads/app.p12", null, false, "191cdc5a8c8c1cb19597a4fd....");

any help ??


Source: (StackOverflow)

Apple push notifications delivery policy

I am working on an iphone messaging application so using APN Servers to send push notification to offline users (as whatsupp does). I am using Enhanced Notification Format to connect APNs via an API (com.notnoop.apns 1.0.0.Beta7-SNAPSHOT version). https://github.com/notnoop/java-apns
https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/LegacyFormat.html

In some cases push notification is not delivered to some devices in a short period of time though everything works fine in my server application, I mean pushnotification byte array is written APNs socket buffer without any problem. At the same time whatsupp can receive push notification properly after that my client application starts receiving notifications from APNS servers. I wonder if something is triggered in APNs after waiting 10 minutes and received whatsup notification.

I know that Delivery of notifications is a “best effort”, not guaranteed but when whatsupp can receive notification why my application sometimes cannot receive. https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/ApplePushService.html#//apple_ref/doc/uid/TP40008194-CH100-SW4

Here is my payload and other parameters:

Expiry:86400
Payload:
{"t":"-13","aps":{"content-available":1,"alert":{"loc-args":["Sender Name John"],"loc-key":"LS_NP"},"sound":"pnsound.aiff","badge":3},"n":"M","m":"NP","j":"905551114444"}

Why I am having this trouble some times? and What I need to check?

Does Apple have an reputation policy in which notification delivered to whatsapp is prioritized?

There is one more notification format (other than both simple and Enhanced) https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/CommunicatingWIthAPS.html This format allows us setting priority format, is this format(IMMEDIATELY) get notification delivered 100%?


Source: (StackOverflow)

What is causing this error when using notnoop's java-apns library?

Code:

<cfset LOCAL.APNSService =
 CreateObject(
 "java",
 "com.notnoop.apns.APNS"
 ).newService(
 ).withCert(
 "MyCert.p12",
 ""
 ).withSandboxDestination().build() />

Exception:

java.io.IOException: failed to decrypt safe contents entry:
       java.lang.ArithmeticException: / by zero 

Stack Trace:

com.notnoop.exceptions.InvalidSSLConfig: java.io.IOException: failed to decrypt safe contents entry: java.lang.ArithmeticException: / by zero
   at com.notnoop.apns.internal.Utilities.newSSLContext(Utilities.java:102)
   at com.notnoop.apns.ApnsServiceBuilder.withCert(ApnsServiceBuilder.java:139)
   at com.notnoop.apns.ApnsServiceBuilder.withCert(ApnsServiceBuilder.java:114)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
   at java.lang.reflect.Method.invoke(Unknown Source)
   at coldfusion.runtime.StructBean.invoke(StructBean.java:511)
   at coldfusion.runtime.CfJspPage._invoke(CfJspPage.java:2300)

Source: (StackOverflow)

Custom push notification sound not playing

I'm using the following payload to send push notification:

{"aps":{"alert":"You got a notification!","sound":"mysound.caf"}}

I have the 'mysound.caf' in www/res/sound/mysound.caf and have added it to the 'Copy bundle resources' section of my app. When I send the notification, it's not played. I keep reading things saying to make sure the sound exists in the 'application bundle' but there's no clear way I can see to do this other than adding it the way I've already done.

I'm registering with:

{"badge":"true","sound":"true","alert":"true","ecb":"onNotificationAPN"}

Any ideas what I could be missing?

Note; I'm also using phonegap which plays the sound correctly once I click through to the app.


Source: (StackOverflow)

Play 2.2 java-apns SSLHandshakeException

My environment is ubuntu 12.04 + Play 2.2.2 + java 7 + java-apns 0.2.3

After I downloaded aps_development from apple and installed to my keyChain, then exported certificate and private key to Dev_Certificates.p12. I put it under conf/certs/Dev_Certificates.p12. This is the error I got:

pool-7-thread-1, WRITE: TLSv1 Handshake, length = 48
pool-7-thread-1, READ: TLSv1 Alert, length = 2
pool-7-thread-1, RECV TLSv1 ALERT:  fatal, handshake_failure
%% Invalidated:  [Session-3, TLS_RSA_WITH_AES_128_CBC_SHA]
pool-7-thread-1, called closeSocket()
pool-7-thread-1, handling exception: javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure
pool-7-thread-1, called close()
pool-7-thread-1, called closeInternal(true)
Thread-13, handling exception: java.net.SocketException: Socket is closed
[error] application - ConnectionClosed MessageID: -1 Error: UNKNOWN
[error] c.n.a.i.ApnsConnectionImpl - Couldn't send message after 3 retries.Message(Id=1; Token=62303732366363653231353337356337313133303637373437643839333738323631626662356139663037633234386366613034346635643737353031376635; Payload={"aps":{"alert":{"loc-args":["angelokh"],"action-loc-key":"REPLY","loc-key":"NEW_MESSAGE_PUSH_FORMAT"},"badge":0},"extra":{"traversableAgain":true,"empty":false}})
javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure
    at sun.security.ssl.Alerts.getSSLException(Alerts.java:192) ~[na:1.7.0_55]
    at sun.security.ssl.Alerts.getSSLException(Alerts.java:154) ~[na:1.7.0_55]
    at sun.security.ssl.SSLSocketImpl.recvAlert(SSLSocketImpl.java:1959) ~[na:1.7.0_55]
    at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1077) ~[na:1.7.0_55]
    at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1312) ~[na:1.7.0_55]
    at sun.security.ssl.SSLSocketImpl.writeRecord(SSLSocketImpl.java:702) ~[na:1.7.0_55]
[error] application - MessageSendFailed Msg: Message(Id=1; Token=62303732366363653231353337356337313133303637373437643839333738323631626662356139663037633234386366613034346635643737353031376635; Payload={"aps":{"alert":{"loc-args":["angelokh"],"action-loc-key":"REPLY","loc-key":"NEW_MESSAGE_PUSH_FORMAT"},"badge":0},"extra":{"traversableAgain":true,"empty":false}}) Exception: javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure

EDIT1:

The p12 file is placed under conf/certs/. The service is created as def function and called by an akka actor.

def apnsService = { 
    val certPath = "certs/DEV-APNS-CERT.p12"
    val baseBuilder =
          APNS.newService()
            .asBatched()
            .withCert(getClass.getResourceAsStream(certPath), "password")
     baseBuilder.withSandboxDestination()
}.build

Source: (StackOverflow)

APNS notification fails to be delivered (error code 8)

When I try to execute an apple push notification on the server I get the following error:

com.notnoop.exceptions.ApnsDeliveryErrorException: Failed to deliver notification with error code 8

My server is a Java application. It is strange that the same server WAR file works OK locally (notifications are sent), but it does not work (with error above) when I deploy it to remote server (RedHat openshift.com).

Here is what I do:

  1. In Xcode I archive my application and export it for Ad Hoc distribution using Distribution Provisioning profile. The profile contains "aps-environment production" entitlement.
  2. In Apple Developer center, I download the APNs production iOS certificate, import it in my iMac Keychain and export a p12 file.
  3. I deploy the .p12 file to my server, where I use https://github.com/notnoop/java-apns library to execute apple push notifications. The library is initialized like this:

APNS.newService().withCert(certificateInputStream,"password").withProductionDestination().withDelegate(this).build();

  1. When run, the client application successfully registeres for push notifications and receives a token.
  2. When the server tries to execute a push notification, an exception is thrown: com.notnoop.exceptions.ApnsDeliveryErrorException: Failed to deliver notification with error code 8

Can you help? What could be the reason that the same setup works on a local but fail on a remote server?


Source: (StackOverflow)

Send push notifications to APNS (AdHoc deployment)

I'm trying to send push notification from my Java backend to my mobile app. For that, I'm using notnoop java-apns library. I managed to set everything up and everything works perfectly on Development (Development certificate and provisioning profile).

I want to release the app soon but first I wanted to setup everything so that I'm ready once it's live. So I created an 'App Store and Ad Hoc' certificate, and also an 'Ad Hoc' provisioning profile. Then I'm trying to use that P12 file which should be the same as the one I will be using once the app is live. But unfortunately I'm getting the following exception:

java.net.SocketException: Connection closed by remote host
    at sun.security.ssl.SSLSocketImpl.checkWrite(SSLSocketImpl.java:1510)
    at sun.security.ssl.AppOutputStream.write(AppOutputStream.java:123)
    at java.io.OutputStream.write(OutputStream.java:75)
    at com.notnoop.apns.internal.ApnsConnectionImpl.sendMessage(ApnsConnectionImpl.java:328)
    at com.notnoop.apns.internal.ApnsConnectionImpl.sendMessage(ApnsConnectionImpl.java:312)
    at com.notnoop.apns.internal.ApnsServiceImpl.push(ApnsServiceImpl.java:46)
    at com.notnoop.apns.internal.AbstractApnsService.push(AbstractApnsService.java:56)
    at com.notnoop.apns.internal.ApnsServiceImpl.push(ApnsServiceImpl.java:36)
    at com.notnoop.apns.internal.AbstractApnsService.push(AbstractApnsService.java:45)
    .....

Anyone know what might be happening? How is it possible to work fine on Development but not AdHoc (and I'm guessing production as well, since they're using the same Push Notification certificate)?


Source: (StackOverflow)

Can we host two APIs (APNs providers) on single machine who send notification to two different apps?

I am very new to iOS app development and APNs. I have developed two apps which are configured to receive push notification.

In my test environment, I am hosting two APIs apiAppX and apiAppY written using Javapns library on same machine. apiAppX and apiAppY generate push notifications(alerts) for appX and appY respectively. I am using different p12 file for different app.

The problem is, if I generate APNs certificate for appX first then it receives notification but appY doesnt. If I generate APNs certificate for appY first then it receives notification but appX doesnt.

I think this issue is being caused because I am hosting two providers on one machine. I came to conclusion after reading this documentation. Especially, after reading following paragraph:

Note that provider connection is valid for delivery to only one specific app, identified by the topic (bundle ID) specified in the certificate. APNs also maintains a certificate revocation list; if a provider’s certificate is on this list, APNs may revoke provider trust (that is, refuse the connection).

Am I right?

Thanks.


Source: (StackOverflow)