|
How2UseJavapns
This article explains how to simply use javapns to send notifications
Deprecated *IMPORTANT*: This page is *deprecated* and therefore contains outdated and/or invalid information. Please go back to the [http://code.google.com/p/javapns/ Project Home] to get access to the latest version and information. Get your certificateIf you wanna use javapns on a PC, the first thing you have to do is exporting your certificate and you private key as a p12 file, using KeyChain on a MAC. To do this, just select both certificate and private key (associated to the application you wish to use to send notifications) in KeyChain, and the right click on one item, and select "Export 2 elements", give a name (for example : myCertificate.p12) and password (for example : p@ssw0rd) and then export as p12. Once you did this, you can now copy this p12 file on your PC (for example C:/temp). Working with javapnsSend a simple notificationDownload javapns, and then add it to your java project classpath. To send notifications, you just need this : 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);
The created payload looks like {"aps":{"sound":"default","alert":"My alert message","badge":45}}
And thats it, enjoy ! Send a 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);
The resulted payload will look like {"aps":{"sound":"default","alert":{"loc-args":["Test1","Test",2],"action-loc-key":"Open App","loc-key":"javapns rocks %@ %@%@"},"badge":45},"acme3":["value1",2],"acme2":42,"acme":"foo"}
|
I'm trying the simple example and I get this exception, any ideas?
java.io.IOException java.io.IOException: failed to decrypt safe contents entry: java.security.NoSuchAlgorithmException?: Cannot find any provider supporting 1.2.840.113549.1.12.1.2
Caused by: java.security.NoSuchAlgorithmException?: Cannot find any provider supporting 1.2.840.113549.1.12.1.2Great API, it works like a charm ! Maybe you may write on your wiki that org.apache.commons.lang is required for this project ? Anyways, good job
Julien Rozé, France
Is there a way to contact you guys directly? I wrote a similar program and would like to trade code.
-Mike
I get this exception when trying run the code above in a main method()...
It doesn't need the specific iPhone's UDID?
Exception in thread "main" Unknown client
What was wrong with my declaration? please e-mai me at:
michaelwilson72 AT gmail.com
@michaelwilson72, You should add the device to PushNotificationManager?, like
It is the device token that has to be added not the udid.
I need some help in device token.whether the device token should be UUID(like 00000000-0000-1000-8000-0016CB957DE5).If i am passing UUID as a parameter its giving number format exception as it was expecting the integer in the send notification method.Can u guys tell me what exactly i need to do here PayLoad? simplePayLoad = new PayLoad?(); simplePayLoad.addAlert("My alert message"); simplePayLoad.addBadge(45); simplePayLoad.addSound("default"); PushNotificationManager?.getInstance().addDevice("my_iPhone", "00000000-00000-1000-8000-0016CB957DE5"); Device client = PushNotificationManager?.getInstance().getDevice("my_iPhone"); PushNotificationManager?.getInstance().initializeConnection("gateway.sandbox.push.apple.com", 2195, "C:/temp/Certificates.p12", "password", SSLConnectionHelper.KEYSTORE_TYPE_PKCS12); PushNotificationManager?.getInstance().sendNotification(client, simplePayLoad);
hello I keep getting this exception: Exception in thread "main" java.lang.NoClassDefFoundError?: org/apache/commons/lang/StringUtils?
Caused by: java.lang.ClassNotFoundException?: org.apache.commons.lang.StringUtils?Hello bilal download commons-lang.jar and place the jar in your classpath
Im getting this on my macbook, the did and token are correct, the cert is choking on something.
java.io.IOException: DER input, Integer tag error
ok my bad I didnt export it....but theres no alert shoing up I only get sound.
Does someone success in passing UTF8 chars within a badge alert? I have got some issues with that. Resulting badges alerts are not well formed. For exemple, if the sended alert is "réussi" it will be transformed in "réussi"
UTF8 works fine, I was using a bad encoding.
I Added FeedbackServiceManager? to the jar and attempted to retrieve the blacklisted devices. But I encountered the error “PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException?: unable to find valid certification path to requested target” Solved this issue with http://blogs.sun.com/andreas/entry/no_more_unable_to_find Then it simply worked fine.
Thanks,
Please help. I keep getting this "Received fatal alert: certificate_unknown" exception when the code tries to write to ssl socket's output stream. I got the certificate from the iPhone developer center, and export them as p12 file from my Mac.
Thank you very much.
I got my problem solved. I used the wrong certificate to make the connection. Another question: according to Mac's document, the socket for the push notification should always be open, but looks like what you're doing here is to quickly open a socket, send the notification, and close the socket. Is this the right way to do thing? by the way, when I tried to get the feedback by using the FeedbackServiceManager?, I got this "sun.security.validator.ValidatorException?: No trusted certificate found" exception. I am using the same p12 certificate for the push notification.
Thank you.
Hi binshu,
I'm not answering your question, sorry, but I'm facing the "certificate_unknown" problem too. Could you please tell me what did you do with your environment. Did you just replace the ".p12" file? What was the right certificate on iPhone developer center and what was wrong? Your facts will truely helps us..
Thank you!
the following is the working code try{
hi Binshu,
Could you please let me know how exactly did you solve the problem? I have everything correctly done but still getting the same error "Received fatal alert: certificate_unknown". It would be great if you can help me stating the step by step procedure.
Thanks in advance.
I had a problem with a jailbroken 3.0 iPhone, the didRegisterForRemoteNotificationsWithDeviceToken was never called.
I installed "Push fix" using Cydia, that fixed it. Hope it helps someone.
I had a problem with a jailbroken 3.0 iPhone, the didRegisterForRemoteNotificationsWithDeviceToken was never called.
I installed "Push fix" using Cydia, that fixed it. Hope it helps someone.
Hi Guys, Great library, it's working really well for me. I now need to get the FeedbackServiceManager? going, but it doesn't seem to be available in the downloadable jar file. Am I doing something wrong? Or do I need to compile from source? If so, do you have any tips for compiling the source in eclipse (I'm not a Java programmer). Thanks, Baz
I was having the "certificate_unknown" problem too - I was my own fault. Make sure you export the two components as one and make sure you're using your push notification certificate and not your developer certificate (although I'm sure no-one else would be that silly!)
Hi everyone, I tried using the library, but can anyone tell me how should be the device token be converted from binary to hex then to string..I have done this but didnt received any notification yet... Even the provider processes everything and I got a response from the provider, but yet no notification.... Did it failed silently? ...This is the code....
NSString dt = [description? stringByTrimmingCharactersInSet:characterSetWithCharactersInString:@"<>"?]; dt = stringByReplacingOccurrencesOfString:@" " withString:@""?; ......Is this correct way of converting?
Hey bazwebb4,
Can you share with me what steps have you followed for the setup. I have done everything required but still not able to receive notifications.
Thanks
Hi, I have some problem in connecting ssl I think
java.io.IOException: toDerInputStream rejects tag type 66
I use the code above and have it put to spring localhost.
Stephen
hi, i am getting the follwing exception when i try to send a notification:
java.io.IOException: DerInputStream?.getLength(): lengthTag=127, too big. java.io.IOException: DerInputStream?.getLength(): lengthTag=127, too big.
Any help is appreciated.
Thanks
ignore my previous post, had the wrong p12 file
Did someone tried what idbill.planx.com suggested? I don't clearly understand the steps. Can someone outline what exactly should be done to get feedback service working. And what should be done to get some data from it? Does it work in a sandbox?
Hi All,
I successfully integrated apple push notification to my application. I used Java server to send pushes to apple's sands box. I used a jar file for building the payload and send the notification to apple's server.
my problem is: Some times I received the push notification so fast and some times it takes like 3 minutes, I really don't know why. I debug my code and i discover that the problem is in a method in the APNS jar which is javapns.back.PushNotificationManager?.sendNotification()
Any one can help me in that , or giving me a hint why that happen
Bilal.Allolo,
The delay doesn't surprise me in the least. Just like SMS messages, email and snail mail, there can be a delay in receiving the message because of the nature of the transport mechanism in place.
On Page 14 of the APNS docs it even alludes to this: Apple Push Notification Service includes a default Quality of Service (QoS) component that per forms a store-and-forward function.
Bill
Hello All, Thanks for the great example. I done testing the push notification and now it is the time for production level. I configured the push notification SSL for production , I import the .p12 to my server side, I changed the url to gateway.push.apple.com, when I run the example my application did not receive a push notification, what I miss ? any one can help Thanks
When we do Device client = PushNotificationManager?.getInstance().getDevice("ourPNSID"); it says client not found.
When we do PushNotificationManager?.addDevice("name","ourPNSID") PushNotificationManager?.getInstance().getDevice("name"); it says device already exists.
Can you clarify?
You mean the new certificate that I use for distribution? if that is what you mean , will I did not. I will try this.
1) I created application ID. 2) Configure it to receive push notification for production. 3) create distribution profile for this application 4) creates a provision file. 5) Run the application using xcode to get a .app. 6) adds the ssl certificate to the server. 7) Send a push notification. No notification reached my iPhone ,,, what is missing?
@Bilal.Allolo you have to close the app
Bilal.Allolo,
So, if the app id changes or the push cert changes, you will need to fetch a new iphoneId.
@idbill.planx.com of course , but the messagebox etc will not apear
Hello, is this push only for notifications of my application residing on iphone?. Is there a way to do the push from my custom calendar on java application server (iCal format data) to the iphone calendar? Thanks in advance
I got the same problem as Bilal.Allolo and it's still not solved. I send a push notification, I get no exception, but I don't receive a notification on my iPhone. Is there any possibility to receive a result message from the Apple Push Notification Service if a psuh notifiaction was sent successfully or not? When I call the FeedbackServiceManager?.getInstance().getDevices() method I got 0 devices. By the way, the FeedbackServiceManager? only works when I assign explicitly the keystore in my Java class via System.setProperty("javax.net.ssl.trustStore", "jssecacerts"); (I created jssecacerts with the class InstallCert?.java which is mentioned above)
I still did not see why the application did not receive a push notification in production mode, while using the same steps for testing on sandbox ,, it works fine, even if my application is opened , I handled that case too. Any one can advice us for a very correct procedure to ward our goal in heaving the push notification for production works .. Thanks
@ Bilal.Allolo: Now I receive notifications! I think that you already receive notifications but you don't notice them. You still have to do:
1. Implement: - (void)applicationDidFinishLaunching:(UIApplication )application { } That means that you register your application for receiving notifications by alert dialog, alert sound and a badget number. 2. On your iPhone, check under "Settings" that you have activated notifications for your application receiving alert dialogs, alert sounds and badget numbers. Please take a look at http://mobiforge.com/developing/story/programming-apple-push-notification-services
Hi All,
The javapns is a good project and it works well with my app several days ago. But today when I tried to use a new cert file to do the push, I met the following erro:
Is there anybody have ever met this issue before?
Thanks in advance.
Hi All,
the changes introduced to allow the use of an InputStream? to initialize the connection (Revision: 22, Author: maxime.peron, Date: 10:44:16, Monday, 30th of November 2009) have broken the retry code in PushNotificationManager?.sendNotifications. The retry code "this.socket = connectionHelper.getSSLSocket()" reads the input stream again, resulting in the following exception:
Caused by: java.io.IOException: DerInputStream?.getLength(): lengthTag=127, too big.
If you want to keep the possibility of loading the keystore from an InputStream?, which is useful for using with getClass().getResourceAsStream(), you'd have to add a factory interface called to return the InputStream?.
Greetings,
Nils
Please ignore my previous post. It is a certificate problem I made in creating the push certificate.
My production server is behind a firewall. Does anyone know what I need to do to get the push notification stuff working when behind a firewall?
I've tried setting the various http.proxyHost, httpProxyPort system properties, but the code in SSLConnectionHelper that creates the socket seems to ignore any proxy settings and attempts to connect directly to the Apple servers.
Any help much appreciated. Running out of hair to tear out :)
when i try to run this program these have a run time error
java.io.IOException: DerInputStream?.getLength(): lengthTag=127, too big.
how can i fix it@idbill.planx.com
Thanks. Yes, Ive tried that. Doesnt seem to work. I can specify any URL, even an invalid one, and it will work on my Dev box.
I get the feeling the http proxy settings arent used by the code that executes a push notification. Is it perhaps because the interface is a binary TCP one, and not a HTTP/HTTPS one?
I recently updated my certificate and now I'm getting this exception:
java.io.IOException: failed to decrypt safe contents entry: javax.crypto.BadPaddingException?: Given final block not properly padded
Caused by: javax.crypto.BadPaddingException?: Given final block not properly paddedFrom what I've found so far, this typically means that the keystore password is incorrect, but I've verified that it is valid by using it to open the p12 file in Portecle.
Anyone else seen this? Could it be a Java 1.5 issue? Any ideas as to what might be wrong with my certificate? I've tried recreating it a few times without luck.
Just a follow-up to the above: I have verified that the issue persists with Java 1.6.
Okay, I'm an idiot. I confused Os and 0s in my password. When I entered the password in Portecle, I read them correctly (i.e., not what was in my code), so it worked.
You'd think I'd have figured this out right away, seeing that every post I could find about this exception was resolved by fixing the password...
I finally got feedback working and thought I'd share some things I've learned in hopes it might save someone else some time:
Method 1: Adding trust for everything
If you just want to get things working, you can modify SSLConnectionHelper.getSSLSocket() to simply trust everything. This makes you vulnerable to a man-in-the-middle attack, but it's quick and has fewer moving parts.
Modify SSLConnectionHelper.getSSLSocket():
// TrustManager class that simply trusts all servers. Obviously this isn't very secure!!! public static class ServerTrustingTrustManager implements X509TrustManager { public void checkClientTrusted( X509Certificate[] chain, String authType ) throws CertificateException { throw new CertificateException( "Client is not trusted." ); } public void checkServerTrusted( X509Certificate[] chain, String authType ) { // trust all servers } public X509Certificate[] getAcceptedIssuers() { return new X509Certificate[0]; } } public SSLSocket getSSLSocket()throws KeyStoreException, NoSuchAlgorithmException, CertificateException, FileNotFoundException, IOException, UnrecoverableKeyException, KeyManagementException { // Load the Keystore KeyStore ks = KeyStore.getInstance(keystoreType); ks.load(new FileInputStream(this.keyStorePath), this.keyStorePass.toCharArray()); // Get a KeyManager and initialize it KeyManagerFactory kmf = KeyManagerFactory.getInstance(ALGORITHM); kmf.init(ks, this.keyStorePass.toCharArray()); // Get the SSLContext to help create SSLSocketFactory SSLContext sslc = SSLContext.getInstance(PROTOCOL); sslc.init(kmf.getKeyManagers(), new TrustManager[] { new ServerTrustingTrustManager() }, null); // Get SSLSocketFactory and get a SSLSocket SSLSocketFactory sslsf = sslc.getSocketFactory(); SSLSocket socket; if (proxySet) { . . . // ommitted for brevity }else{ socket = (SSLSocket) sslsf.createSocket(appleHost, applePort); } return socket; }Method 2: Adding trust specifically for the Apple feedback certificate
If you want to check the Apple feedback certificate when initiating the SSL connection, you can do the following:
(1) Use the InstallCert.java file described above by Bill (Nov 27, 2009) to obtain the Apple feedback certificate.
(2) Add the certificate to your push notifications certificate keystore (*.p12). You can use the Java command-line utility keytool, but it's much easier to use Portecle.
(3) Download the BouncyCastle? crypto library for JDK 1.5 or JDk 1.6. Add it to your project's classpath.
(4) As described in the BC installation instructions, you will need to modify SSLConnectionHelper.java to add the BC security provider. You can do this with a static initializer somewhere inside the SSLConnectionHelper class:
static { Security.addProvider(new BouncyCastleProvider()); }(5) Make a copy of the SSLConnectionHelper.getSSLSocket() method that will be used to get SSL sockets for feedback. The only difference will be that it will use your keystore to check trust, by initializing a TrustManagerFactory? with your keystore and passing its trust managers to the SSLContext init method. For brevity I have omitted the portion of getSSLSocket() that provides proxy support -- if (proxySet) { . . . } -- but it should still work fine here too.
public SSLSocket getFeedbackSSLSocket()throws KeyStoreException, NoSuchAlgorithmException, CertificateException, FileNotFoundException, IOException, UnrecoverableKeyException, KeyManagementException { // Load the Keystore try { KeyStore ks = KeyStore.getInstance(keystoreType, "BC"); ks.load(new FileInputStream(this.keyStorePath), this.keyStorePass.toCharArray()); } catch( NoSuchProviderException e ) { throw RuntimeException( e ); } // Get a KeyManager and initialize it KeyManagerFactory kmf = KeyManagerFactory.getInstance(ALGORITHM); kmf.init(ks, this.keyStorePass.toCharArray()); // Get a TrustManagerFactory and init with KeyStore TrustManagerFactory tmf = TrustManagerFactory.getInstance( ALGORITHM ); tmf.init( ks ); // Get the SSLContext to help create SSLSocketFactory SSLContext sslc = SSLContext.getInstance(PROTOCOL); sslc.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null); // Get SSLSocketFactory and get a SSLSocket SSLSocketFactory sslsf = sslc.getSocketFactory(); SSLSocket socket = (SSLSocket) sslsf.createSocket(appleHost, applePort); return socket; }(6) Finally, modify FeedbackServiceManager?.getDevices() to use your new socket method:
One more thing: as Nils reported on Jan 28, 2010, the changes in r22 to support an InputStream? have broken the retry code in PushNotificationManager?.sendNotification(). On the second try, DerInputStream? throws an IOException.
The workaround for this is either to first call pushNotificationManager.setRetryAttempts(1) or, if you don't need to create the keystore from an InputStream?, just revert to r21.
I got everything to run fine, but didnt see any sort of a push message. Perhaps some logging to know if things went OK or not would be in order. Looking at wireshark traces I dont see the payload anywhere so I am thinking there was an issue, but I dont know where to start checking.
When sending the simple notification I get the the sounds that dings, and the badge bubble works too. But I dont actually get any message to pop up. Anyone have any ideas?
FYI if I call toString() the alert looks like: {"aps":{"sound":"default","alert":"nothing shows up","badge":1}}
Bill, thanks for making these improvements. This project is tremendously useful.
It looks like you fixed the broken retry code by instantiating the FileInputStream? in SSLConnectionHelper.getSSLSocket(). The problem in r22 was that this method, which is called during the retry, was attempting to reload the keystore with the same stream it loaded it from previously. On the second try, there would be nothing left in the stream, resulting in an IOException.
If you still want to provide the ability to pass in an input stream, you could create the keystore (or even the SSLSocketFactory) in the constructor, so that getSSLSocket() can get a new socket without having to reference the stream again.
try here as i seemed to have dropped a comment off in the wrong place...is there anything specific to java 1.6 that might prevent javapns compiling on another (older) JDK?
thanks.
Hi
i am getting the follwing exception when i try to send a notification:
java.io.IOException: DerInputStream??.getLength(): lengthTag=127, too big.
Any help is appreciated.
Thanks
The wiki is being expanded... please visit Intro before posting here.
Post questions/problems as issues under the issues tab... See Help
Same error
java.io.IOException: DerInputStream???.getLength(): lengthTag=109, too big.
using http://blogs.sun.com/andreas/resource/InstallCert.java to retrieve the certificate of feedback.sandbox.push.apple.com
The wiki is being expanded... please visit Intro before posting here.
Post questions/problems as issues under the issues tab... See Help
The current (4/23/2010) trunk implementation of the feedback service is not quite right, apparently. It contains this code to read from the service:
However, SSLSocketInputStream.available() can return zero even if input data is waiting to be read. See:
http://forums.sun.com/thread.jspa?threadID=5428561
I'd recommend changing the code to:
Hi,
thanks in advance.
shepherdcrane?, to avoid DuplicateDeviceException?, use: pushManager.removeDevice("yourdevice");
Hi irtt.senthil, I have same problem, but on development
thanks in advance.
Im in the same situation of you riri... help us !
javaapns client already exists
I have gotten javapns working in my PC dev environment. Works like a charm. Now, however, I am trying to port it to my Android phone. Yeah, I know it sounds silly, pushing from an Android to an iPhone. Anyway, here's what I've found:
There seems to be a problem with log4j in Android. It runs out of memory and crashes in the build. So, I've changed all the logs to printlns. Also, I have had to change the KeyManagerFactory? ALGORITHM from "SunX509?" to "X509". Apparently the PC jre has some Sun libs that are not on Android. Now it builds fine and runs. However, now I am getting the following exception trying to write my push message.
The SSLSocket opens just fine, but the exception happens when trying to open the OutputStream?. Anybody seen this before?
Looking in debug, the push cert and the distribution cert show up as trusted. However, my private key file shows up with isTrusted=false. On Android, the provider is BouncyCastle?, whether I add the bcprov lib to my build path.
This is my first SSL project, so these questions may seem rudimentary. But, I would greatly appreciate any help getting around this problem.
Thanks in advance.
Dave
hi guys, I managed to run the demo, and send push notification. while trying to do this under the google app engine i got an exception as :
java.lang.ExceptionInInitializerError?
Caused by: java.security.AccessControlException?: access denied (java.security.SecurityPermission? putProviderProperty.BC)any help please.
@alhalayqa
I am afraid that you are not authorized to open an arbitrary outgoing connection using the App Engine. You are just authorized to do very limited things (like basic HTTP and HTTPS outgoing connections). I suppose this is the problem that you are getting.
If you need a possibility to send push notifications from the App Engine, you can use a service like Urban Airship. It's free up to a certain point.
hi all,
I am wondering what is the standard workflow with Javapns to send a fair amount (e.g. 10'000) of notifications to different devices. Am I supposed to do batches of X notifications (e.g. 100), and open and close each time the connection before and after, then start again for the next batch? I suppose there is a limit about the number of notifications that Javapns (or Apple servers) can handle within the same connection (if yes, what is it)? Or does Javapns takes care about that itself?
Thanks in advance. Cheers,
my server does not give any errors BUT
I send the notification successfully from my provider to apple sandbox server but my client doesn't receive any notification
Running javapns version 1.6.3 and I have looked at the Wiki Help and Intro.
Still getting this error: Caused by: java.io.IOException: DerInputStream?.getLength(): lengthTag=109, too big.
Any help would be appreciated.
Any comments here are ignored. Create a ticket to get answers.
any one meet with problems like follows:
" failed to decrypt safe contents entry: java.io.IOException: getSecretKey failed: PBE SecretKeyFactory? not available"
I have generated a .p12 file (on a mac) and am able to connect to apple push server without any issues on a windows machine.
But when i use the same on a linux box i get this error :
java.io.IOException: DerInputStream?.getLength(): lengthTag=127, too big
Do I need to generate some other certificate or file for linux ????
i just spend a half day finding out why my app doesnt receive push notifications. Everything was allright. No errors. But the notification didnt arrive on my test device. Finally i found out why. The time-settings on the device where wrong.
Check the time settings on your test-device if the pushnotification doesnt arrive
I am not sure how this is supposed to work. I can send a push the first time, but if I try again, I get a Client already exists error. Presumably because I added the device the first time around. So I tried to fix it by calling getDevice, then check if it's null before adding the device. However, now I am getting an unknown client exception.
PushNotificationManager pushManager = PushNotificationManager.getInstance(); // in javapns the device must have an id which apparently is unique. I am therefore using the token for the id and the token so pushManager doesn't barf. Device dev = pushManager.getDevice(deviceToNotify.deviceToken()); if(dev == null) pushManager.addDevice(deviceToNotify.deviceToken(), deviceToNotify.deviceToken());Ok, I solved that particular issue, though I still don't know what was intended. Now I'm trying to use the feedback example, but nothing seems to be happening. I am using it in the sandbox, but i am getting no devices back in my response, regardless of whether the devices have turned off notifications, been uninstalled, or what.
How is this supposed to work? Does the sandbox provide feedback? How can this be tested?
I've just solved my problem in using javapns. Solution could be interesting for someone else. I've read almost all info in code.google.com/p/javapns/wiki. I've done all things I've read to get notification on my iPhone. But I have not got it.
My mistake was the following. I've launched my iPhone app. It sends a signal to provider. Provider in turn sends push notification to the APNs. I've been waiting for some alert on my iPhone display but I've saw my usual app view.
Solution for me was the following. I've added delegate method
- (void)application:(UIApplication *)app didReceiveRemoteNotification:(NSDictionary *)notif {
}to the app delegate implementation file. Then I opened Console window in XCode, rebuild and restart my iPhone. And push notification was received indeed.
Depends on my company's network policy, i need to access APNs through proxy. so i add proxy setting as below: this.pushManager.setProxy(proxyHost, proxyPort); But proxy response error: startAPNManager Start APN manager create error: Unexpected EOF from proxy
first of all, i promise that my code is right, i test to access APNs directly without proxy, and i got notification on my iPhone. So what's wrong with my code? Is there any advices?
I encountered one strange problem. PushNotificationManager?.getInstance().sendNotification(client, simplePayLoad); //My device can receive the message, but the application stopped after above line System.out.println("message sent"); //This line not executed
I tired the simple APNS code that describe in simple example but kept getting socket connection already close. Do anyone know what m'I doing wrong?
Ok i've finally solve the certificate issue but look like i've same issue previous user, i don't get the control back to my app after i call the method pushManager.sendNotification( client, aPayload )
Anything we need to do while initializeConnection ?
This is a known issue with 1.6 (see issue #54 ), which has been fixed in 2.0 (Beta). If you can upgrade to that version, the issue should disappear.
Can I use this API for an Androi App. If yes then please send me how. Thanks...
No you cannot.
Hi I'm getting the below exception when i try to access apns. I dont have any clue. Anyone will be really appreciated. "ERROR javapns.notification.PushNotificationManager? - Delivery error : javapns.communication.exceptions.InvalidCertificateChainException?: Invalid cer tificate chain (Received fatal alert: certificate_unknown)! Verify that the key store you provided was produced according to specs..."
As stated at the top of this document, this page is deprecated and refers to an old version of JavaPNS. Please visit the project's web site to get the latest version and documentation. If you have an issue with the use of JavaPNS, please open an issue report in the Issues section.