Problem sending Apple Push Notification using Java and REST.

Hello there,
Am using the javapns library to send an Apple Push Notification through a REST based web service...
Here are the steps that I have completed:
iPhone Developer Program Portal (IDPP):
(1) Created the App ID and APNS based SSL Certificate and Keys.
(2) Created and installed the provisioning profile.
(3) Installed the SSL Certificate and Key on the server.
(4) Set up my iPhone app to register for remote notifications.
XCode:
Was able to obtain my device token when I built and deployed my app onto my device.
As soon as my iPhone app deployed, the dialog came up on my iPhone indicating that my app would like to send push notifications and also asked for permission to allow them.
When I invoked my web service, through my Log4J statements, I was able to see that my REST based web service was indeed invoked but I never received a push notification on my iPhone app!
ApnsManager class:
public class ApnsManager {
    /** APNs Server Host **/
    private static final String HOST = "gateway.sandbox.push.apple.com";
    /** APNs Port */
    private static final int PORT = 2195;
    public void sendNotification(String deviceToken)
    throws Exception {
       try {
           PayLoad payLoad = new PayLoad();
           payLoad.addAlert("My alert message");
           payLoad.addBadge(45);
           payLoad.addSound("default");
           PushNotificationManager pushManager =
              PushNotificationManager.getInstance();
           pushManager.addDevice("iPhone", deviceToken);
           log.warn("Initializing connectiong with APNS...");
           // Connect to APNs
           pushManager.initializeConnection(HOST, PORT,
           "/etc/Certificates.p12", "password",
           SSLConnectionHelper.KEYSTORE_TYPE_PKCS12);
           Device client = pushManager.getDevice("iPhone");
           // Send Push
           log.warn("Sending push notification...");
           pushManager.sendNotification(client, payLoad);
           pushManager.stopConnection();
       catch (Exception e) {
           e.printStackTrace("Unable to send push ");
RESTful Web Service:
@Path(ApnService.URL)
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public class ApnService {
    public static final String URL = "/apns";
    @GET
    @Path("send")
    @Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
    public String send() throws JSONException, IOException {
        String msg = "";
        try {
            log.debug("Inside ApnService.send() method.");
            log.debug("Sending notification to device");
            ApnManager.sendNotification("32b3bf28520b977ab8eec50b482
            25e14d07cd78 adb69949379609e40401d2d1de00000000738518e5c
            000000003850978c38509778000000000000000000398fe12800398f
            e2e0398fe1040000");
         } catch(Exception e ) {
               e.printStackTrace();
               msg = "fail";
         msg = "success";
         StringWriter sw = new StringWriter();
         JsonFactory f = new JsonFactory();
         JsonGenerator g = f.createJsonGenerator(sw);
         g.writeStartObject();
         g.writeStringField("status", msg);
         g.writeEndObject();
         g.close();
         return sw.toString();
}Now, when I deploy my app to my app server and open up a rest client and type in:
http: // localhost:8080/myapp/apns/send
The rest client returns this:
HTTP/1.1 200 OK
The following log messages are outputted to my console:
01:47:51,985 WARN  [ApnsManager] Initializing connectiong with APNS...
01:47:52,318 WARN  [ApnsManager] Sending push notification... However, I don't receive the push notification on my app (residing on my iPhone)!
Am really stumped at this point...
What could I possibly be doing wrong? :(
Is it a problem with the way I set up my RESTful web service (sorry I am a newbie to REST)?
Would really appreciate it if someone could assist me with this...
Thank you for taking the time to read this...

Please show me where is answer for this..

Similar Messages

  • I am having problem with my push notifications of facebook and other applications on my 3gs ios5.0

    Hi,
    I am having problem with my push notifications of facebook and other applications on my 3gs ios5.0 device. I have done too many things have updated my facebook application but still it is not showing any push notification. Is there any settings that i need to do for it? Also it is not allowing me to show on mobile in facebook. Any one here can help?

    ok for facetime and imessage go into settings turn them off make sure to make an icloud backup and then go to settings general erase all content and settings and then set it up from the backup it should activate your imessage and facetime

  • Apple push notification service problem

    Hi all,
    I'm trying to implement notification push service to my app.
    I'm reading here:
    http://mobiforge.com/developing/story/programming-apple-push-notification-servic es
    and here:
    https://developer.apple.com/library/ios/#documentation/NetworkingInternet/Concep tual/RemoteNotificationsPG/Introduction/Introduction.html#//apple_ref/doc/uid/TP 40008194-CH1-SW1
    When I try to connect to the sandbox service server with my php code:
    [code]
    <?php
          $token = $_GET['myapptoken'];
          $deviceToken = $token; // token dell'iPhone a cui inviare la notifica
          // Passphrase for the private key (ck.pem file)
           $pass = "mypass";
          // Get the parameters from http get or from command line
          $message = 'Notification text';
          $badge = 1;
          $sound = 'default';
          // Construct the notification payload
          $body = array();
          $body['aps'] = array('alert' => $message);
          if ($badge)
                $body['aps']['badge'] = $badge;
          if ($sound)
                $body['aps']['sound'] = $sound;
          /* End of Configurable Items */
          $ctx = stream_context_create();
          stream_context_set_option($ctx, 'ssl', 'local_cert', 'apns-dev.pem');
          // assume the private key passphase was removed.
          stream_context_set_option($ctx, 'ssl', 'passphrase', $pass);
          $fp = stream_socket_client('ssl://gateway.sandbox.push.apple.com:2195', $err, $errstr, 120, STREAM_CLIENT_CONNECT, $ctx);
          if (!$fp) {
                print "Failed to connect $err $errstrn";
                return;
          } else {
                print "Connection OK\n";
          $payload = json_encode($body);
          $msg = chr(0).pack('n',32).pack('H*', str_replace(' ', '', $deviceToken)).pack('n',strlen($payload)).$payload;
          print "sending message :" . $payload . "\n";
          fwrite($fp, $msg);
          fclose($fp);
    ?>
    [/code]
    I receive this message:
    Warning: stream_socket_client(): unable to connect to ssl://gateway.sandbox.push.apple.com:2195 (Connection timed out) Failed to connect 110

    Please show me where is answer for this..

  • Can i use APNS certificates created by the "Apple push certificates portal" to send regular push notifications to my iphone app (not MDM related)?

    Can i use APNS certificates created by the "Apple push certificates portal" to send regular push notifications to my iphone app (not MDM related)?
    The push notifications are sent from servers of my customers and i don't want to give them my own push cert (with the private key)

    As KiltedTim mentioned you should be "good to go" in a couple weeks when IOS 8.0 is released to the public for your iPad.  Here's more info.  Scroll down to the "Send any kind of text message from any of your devices"  section:
    https://www.apple.com/ios/ios8/continuity/

  • I was on a free dictionary website and it asked me if it would like to send me push notifications and i allowed it but i don't want them anymore...how do i get rid of that? I'm using my macbook pro by the way

    I was on a free dictionary website and it asked me if it would like to send me push notifications and i allowed it but i don't want them anymore...how do i get rid of that? I'm using my macbook pro by the way

    Go to the site and look for an unsubscribe link. Or, contact the site and ask them to stop.

  • TS3899 With Yahoo Mail, and anotare account (Inacap Mail), I can only receive mails but I can't send emails. I don't know if this is a problem of the iPad or it is a problem with yahoo mail, because using Gmail and the email of my job I don' have this pro

    With Yahoo Mail, and anotare account (Inacap Mail), I can only receive mails but I can't send emails. I don't know if this is a problem of the iPad or it is a problem with yahoo mail, because using Gmail and the email of my job I don' have this problem.

    Google them to confirm the settings that you need for the outgoing server, then check the setting you entered on the pad.  Pay real close attention to the outgoing server name, and port.  You may need to change in on the pad. 

  • Sending udp packets using java and receiving it using c

    hi,
    Is it possible to send udp packets using java and receive the same using c??????? if yes.... plz help immediately.

    The biggest issue is data format. The JVM is big endian, with 16-bit characters. The machine running 'C' could be almost anything. A (signed!) byte array is probably the easiest unit of exchange.
    The Java program has its own techniques for storing/retrieving data to/from the byte array - and the C program has its own techniques. ASCII Strings are often the easiest to exchange - just convert the java String objects to byte array and send them.
    apaliwal1 has already given the UDP calls to send/receive the data.

  • Iphone doesnt send me push notification

    i have iphone 4 and now ios 7.0.4
    the problem occured first when i was using ios 7.0.3
    i am receiving whatsapp messages only if i open whatsapp. I checked everything and wrote to the whatsapp support. they said to erase everything on the phone and dont use my backup so just install agan the whatsapp. it worked, but i wasnt happy as all my phoos emails files music apps everything gone just becuase of the erase. so i used my backup and now i have everything back but whatsapp still only send me push notification if i open it.
    can you guys help me? it drives me crazy.

    Try:
    My IOS 7 Push notifications are not...: Apple Support Communities

  • Invalid device in Apple push notification

    We have done an apple  push notification for an iphone application and its working fine.Using the APNs certificate, it is displaying the push message. Suppose the corresponding application is uninstalled from a particular device and I don't want to push the message to that device any more. How could I identify whether the device to which the messages are send is valid?
    Any sample CF code or link for this is appreciated.

    Greetings Prem garigapati,
    I understand you are receiving a message regarding an expiring certificate. Are you using a version of OS X Server on your computer? This article has additional information which may be helpful:
    OS X Server: How to renew expired push certificates - Apple Support
    If the certificate you use with the Apple Push Notification service (APNs) has expired, you can renew it using OS X Server.
    Use these steps to renew any push notification certificates that have expired:
    Open the OS X Server app.
    Select your server in the Server app sidebar, then click Settings.
    Click the Edit button next to the “Enable Apple push notifications” option.
    Enter your organization's Apple ID in the sheet that appears, then click Renew to renew the expired certificate.
    Deselect (uncheck) the “Enable Apple push notifications” option.
    Select (check) the “Enable Apple push notifications” option.
    Thank you for contributing to Apple Support Communities.
    Best,
    Bobby_D

  • Apple Push Notification Services SSL error

    Hi all,
    I used APNS to Push Notification to my iOS App, and i take some error.
    When i send push to iOS App by Web service, I can't connect to Apple Push Server.
    This is tutorial : https://www.youtube.com/watch?v=_3YlqWWnI6s
    This is my php code :
    <?PHP
    if($_POST['message']){
      $deviceToken = 'xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx';
      $message = stripslashes($_POST['message']);
      $payload = '{
      "aps" :
      { "alert" : " '.$message.' ",
      "badge" : 1,
      "sound" : "bingbong.aiff"
      $ctx = stream_context_create();
      stream_context_set_option($ctx, 'ssl', 'local_cert', 'ck.pem');
      stream_context_set_option($ctx, 'ssl', 'passphrase', 'xxxxxxxx');
      $fp = stream_socket_client('ssl://gateway.sandbox.push.apple.com:2195', $err, $errstr, 60, STREAM_CLIENT_CONNECT, $ctx);
      if(!$fp){
      print "Failed to connect $err $errstrn";
      return;
      }else{
      print "Notifications sent!";
      $devArray = array();
      $devArray[] = $deviceToken;
      foreach($devArray as $deviceToken){
      $msg = chr(0) . pack("n",32) . pack('H*', str_replace(' ', '', $deviceToken)) . pack("n",strlen($payload)) . $payload;
      print "sending message :" . $payload . "n";
      fwrite($fp, $msg);
      fclose($fp);
    ?>
    <form action="sendnotification.php" method="post">
      <input type="text" name="message" maxlength="100">
      <input type="submit" value="Send Notification">
    </form>
    What is my wrong?
    Thanks in advance,
    --DevirosVR--

    You mean Server.app? Yeah unless there is another 'Enable Apple push notifications' checkbox somehere else. But just to clarify, I have cecked the 'Enable Apple push notifications' checkbox in Server.app->My Server->Settings.

  • Does the new command 2 binary format work with Apple Push Notification Service? I receive an invalid response status code of 128.

    Does the new command 2 binary format work with Apple Push Notification Service? I am sending 2 messages with the same payload to 2 different devices. None of the messages display on either of the devices. It seems that at least 3 should have been displayed. For my first device, I received a response with an invalid status code of 128 and the message identifier is 2 indicating that the first message was OK. However no message was displayed on the phone. For the second device, I did not receive any error response, but no message was displayed on the device.
    Does ANS perform any validation on the message identifier? The Local and Push Notification Programmin Guide says the message identifier is:
    An arbitrary, opaque value that identifies this notification. This identifier is used for reporting errors to your server.
    I know that the device tokens are valid because the same tokens work when I use the legacy basic or enhanced formats. The phones display the messages correctly when I send to ANS using the old ANS message format.
    Here is the data and the response:
    Sent to ANS: 2 0 0 0 158 1 0 32 120 107 166 143 171 157 143 169 70 135 12 135 246 142 64 224 244 44 116 4 154 65 115 192 206 28 189 56 174 0 172 16 2 0 23 123 34 97 112 115 34 58 123 34 97 108 101 114 116 34 58 34 65 66 67 34 125 125 3 0 4 0 0 0 2 4 0 4 83 7 119 141 5 0 1 5 1 0 32 120 107 166 143 171 157 143 169 70 135 12 135 246 142 64 224 244 44 116 4 154 65 115 192 206 28 189 56 174 0 172 16 2 0 23 123 34 97 112 115 34 58 123 34 97 108 101 114 116 34 58 34 65 66 67 34 125 125 3 0 4 0 0 0 3 4 0 4 83 7 119 141 5 0 1 5
    ANS returned an error: 8 128 0 0 0 2
    Sent to ANS: 2 0 0 0 158 1 0 32 4 239 182 26 13 237 170 136 41 243 181 57 120 208 135 19 101 102 212 70 55 244 251 255 160 125 82 9 10 143 72 17 2 0 23 123 34 97 112 115 34 58 123 34 97 108 101 114 116 34 58 34 65 66 67 34 125 125 3 0 4 0 0 0 5 4 0 4 83 7 119 147 5 0 1 5 1 0 32 4 239 182 26 13 237 170 136 41 243 181 57 120 208 135 19 101 102 212 70 55 244 251 255 160 125 82 9 10 143 72 17 2 0 23 123 34 97 112 115 34 58 123 34 97 108 101 114 116 34 58 34 65 66 67 34 125 125 3 0 4 0 0 0 6 4 0 4 83 7 119 147 5 0 1 5
    ANS did not return a response.

    Hello, can you please help me ?
    You specified sample payload here:
    TerrellFromLockhart wrote:
    I finally got this to work. The picture in the Programming Guide is very confusing. The solution was to prefix every message's frame data with command 2 and that messsage's frame data length. Here is a sample:
    ANS frame: 2 0 0 0 77 1 0 32 120 107 166 143 171 157 143 169 70 135 12 135 246 142 64 224 244 44 116 4 154 65 115 192 206 28 189 56 174 0 172 16 2 0 21 123 34 97 112 115 34 58 123 34 97 108 101 114 116 34 58 34 63 34 125 125 3 0 4 0 0 0 2 4 0 4 83 7 199 195 5 0 1 10 2 0 0 0 77 1 0 32 120 107 166 143 171 157 143 169 70 135 12 135 246 142 64 224 244 44 116 4 154 65 115 192 206 28 189 56 174 0 172 16 2 0 21 123 34 97 112 115 34 58 123 34 97 108 101 114 116 34 58 34 63 34 125 125 3 0 4 0 0 0 3 4 0 4 83 7 199 195 5 0 1 10 2 0 0 0 77 1 0 32 120 107 166 143 171 157 143 169 70 135 12 135 246 142 64 224 244 44 116 4 154 65 115 192 206 28 189 56 174 0 172 16 2 0 21 123 34 97 112 115 34 58 123 34 97 108 101 114 116 34 58 34 63 34 125 125 3 0 4 0 0 0 4 4 0 4 83 7 199 195 5 0 1 10
    About to read response at Thu Feb 20 15:40:20 CST 2014
    SocketTimeoutException
    2 - is clearly command
    0 0 0 77 - frame length
    1 - item Id
    what's 0 32 ? According to this page https://developer.apple.com/library/ios/documentation/NetworkingInternet/Concept ual/RemoteNotificationsPG/Chapters/Commu…
    Item id  should be followed by item length. But item length is obviously greater than 32 because device token's length is 32. Can you please explain why 0 32 were used? and do you have any insight on item id meaning ?

  • Apple Push - What is it and why do I need it?

    I have recently noticed a new "Apple Push" program in my processes that seems to start with startup on my Windows Vista SP2 machine with iTunes 10.5.3.3 installed. The only Apple products I use are iTunes/Quicktime with my 4th Gen iPod Nano so this program could have only stemmed from iTunes. A quick Google search and speed-read of a Wikipedia entry tells me it is related to the Apple Push Notification Service (APNS) for Apple devices.
    What I want to know is what does it do and do I need it? I do not currently own an iPhone or any Apple device that receives notifications, so if all it does is push notifications to devices, do I really need it to run on startup and continue on in the background all the time? Can I disable it (at least while I don't own any iOS devices)? Or does it do something else I am unaware of that I need it for?
    Any advice would be appreciated

    Growl is a third party utiltiy for manipulating parts of the OS and displaying "notifications". It sounds like you once had it installed. To remove go here...
    http://growl.info/documentation/growl-package-removal.php
    EDIT: It's not your system telling you, it's a Growl notification.
    -mj
    Message was edited by: macjack

  • I wanted to send a push notification, unfortunately it does not work. The page will not load. Anyone know why?

    I wanted to send a push notification, unfortunately it does not work. The page will not load. Anyone know why?

    Push notifications, I believe, is only for iOS.
    If it is for iOS, take a look at Using Apple push notifications with Digital Publishing Suite | Adobe Developer Connection

  • Apple Push Notification

    Hi,
    I am using Apple push notification service.Its working fine,But when application run in background and got the notification,the delegate method didFinishLaunchingWithOptions didn't get call when launch the application by pressing application icon.Notification didn't have alert.
    Please provide suggestions.

    If you bring app back from background to the foreground, "applicationWillEnterForeground" is called instead of "didFinishLaunchingWithOptions", because the app is already launched, you will have to force quit the application before you can re-launch the app again.
    I hope this helps

  • *HELP* - Apple Push Notification Service certificates

    For several times now I received the following Message from "[email protected]":
    The following Apple Push Notification Service certificates, created for AppleID [email protected] will expire on March 14, 2015. Revoking or allowing this certificate to expire will require existing devices to be re-enrolled with a new push certificate. You can renew your certificates with your OS X server administration tools. macserver.local - apns:com.apple.calendar
    macserver.local - apns:com.apple.contact
    macserver.local - apns:com.apple.mail
    macserver.local - apns:com.apple.mgmt
    macserver.local - apns:com.apple.alerts
    What does it mean? Where does it come from? I have absolutely no idea?
    The only thing that comes into my mind was the exchange of my old TimeCapsule with a MacMini as a Fileserver last year. Those days I played a little with OS Mavericks Server, but finally didn't use it. I didn't even purchase the Server App for Yosemite. Is this any sort of "artefact" from my Server exploration activities? Is there any risk that my poor Mac will explode and kill me on March 14??????????

    Server.app > select the server at the top of the left column > select Settings > select the Edit button to the right of enable Apple Push Notification > select Renew.
    FWIW, I've previously logged an enhancement request with Apple, as this mechanism involves certificates, and isn't available on the certificates page within Server.app, nor is there a way to access the settings from the alert.  This renewal mechanism just isn't as easy to find as it should be.  You're not the first to be confounded by this stuff, in other words.

Maybe you are looking for