Safari Push notification never displays

Hello,


I made a push package (Safari push package) which seems to work.


I try to now send a notification but it ne ver displays on my screen.


I checked the apsd.log file and I can see the information relative to my notification, but then, nothing happens on my screen.

I receive other notifications from other websites without any problem.


##############################################################

Here is a part of the apsd.log :


Mar 29 10:12:30 ced usernoted[314]: ApplePushService: <APSConnection: 0x7fb2ca43d230> Delivering message from apsd: <APSIncomingMessage: 0x7fb2ca507490> 0 web.com.spa$
Mar 29 10:12:30 ced usernoted[314]: ApplePushService: <APSConnection: 0x7fb2ca43d230> responding with an ack for message with guid 58727DBF-3FC5-46CA-BB35-4AD010A444CF
Mar 29 10:12:30 ced usernoted[314]: ApplePushService: <APSConnection: 0x7fb2ca43d230> making delegate (<PNPushNotificationConnection: 0x7fb2ca60cce0>) calls to delive$
            aps =     {
                alert =         {
                    action = viewed;
                    body = tata5;
                    title = toto4;
                };
            };
            "url-args" =     (
                "www.spartoo.com"
            );
        } for topic web.com.spartoo
Mar 29 10:12:30 ced apsd[89]: <APSCourier: 0x7fd1d86204f0> informed that <APSConnectionServer: 0x7fd1d8747ee0> acknowledges incoming message with guid 58727DBF-3FC5-4$
Mar 29 10:12:30 ced usernoted[314]: ApplePushService: <APSConnection: 0x7fb2ca43d230> calling <PNPushNotificationConnection: 0x7fb2ca60cce0>connection:didReceiveMess$
Mar 29 10:12:30 ced apsd[89]: <APSMessageStore: 0x7fd1d8644330> Removing incoming message with guid 58727DBF-3FC5-46CA-BB35-4AD010A444CF
Mar 29 10:12:30 ced usernoted[314]: ApplePushService: <APSConnection: 0x7fb2ca43d230> returned from <PNPushNotificationConnection: 0x7fb2ca60cce0> connection:didRecei$
Mar 29 10:12:30 ced apsd[89]: APSMessageStore - APSIncomingMessageRecordDeleteMessageForGUID 58727DBF-3FC5-46CA-BB35-4AD010A444CF
Mar 29 10:12:33 ced apsd[89]: Changing to power assertion type ApplePushServiceTask
Mar 29 10:16:49 ced apsd[89]: <APSCourier: 0x7fd1d86204f0>: Sending keep alive message via tcpStream: <APSTCPStreamMaster: 0x7fd1d863f9d0>
Mar 29 10:16:49 ced apsd[89]: <APSCourier: 0x7fd1d86204f0>: Outstanding data received: <0d000000 00> (length 5)
Mar 29 10:16:49 ced apsd[89]: <APSCourier: 0x7fd1d86204f0>: Stream processing: complete yes, invalid no, length parsed 5, parameters {
            APSProtocolCommand = 13;
        }
Mar 29 10:16:49 ced apsd[89]: <APSCourier: 0x7fd1d86204f0>: Received successful keep-alive response {
            APSProtocolCommand = 13;
        }
Mar 29 10:16:49 ced apsd[89]: <APSCourier: 0x7fd1d86204f0>: Stream processing: complete no, invalid no, length parsed 0, parameters (null)
Mar 29 10:21:08 ced apsd[89]: <APSCourier: 0x7fd1d86204f0>: Sending keep alive message via tcpStream: <APSTCPStreamMaster: 0x7fd1d863f9d0>
Mar 29 10:21:08 ced apsd[89]: <APSCourier: 0x7fd1d86204f0>: Outstanding data received: <0d000000 00> (length 5)
Mar 29 10:21:08 ced apsd[89]: <APSCourier: 0x7fd1d86204f0>: Stream processing: complete yes, invalid no, length parsed 5, parameters {
            APSProtocolCommand = 13;
        }
Mar 29 10:21:08 ced apsd[89]: <APSCourier: 0x7fd1d86204f0>: Received successful keep-alive response {
            APSProtocolCommand = 13;
        }
Mar 29 10:21:08 ced apsd[89]: <APSCourier: 0x7fd1d86204f0>: Stream processing: complete no, invalid no, length parsed 0, parameters (null)
Mar 29 10:22:30 ced apsd[89]: APSMessageStore - Saving database.
Mar 29 10:22:30 ced apsd[89]: APSMessageStore - Destroying database.
Mar 29 10:22:30 ced apsd[89]: APSMessageStore - Closed database.
Mar 29 10:22:30 ced apsd[89]: APSMessageStore - Reopening database
Mar 29 10:22:30 ced apsd[89]: APSMessageStore - Initializing database on thread: <NSThread: 0x7fd1d8645680>{number = 359, name = (null)}
Mar 29 10:22:30 ced apsd[89]: APSMessageStore - Enabling auto vacuum.
Mar 29 10:22:30 ced apsd[89]: APSMessageStore - Enabling WAL journal mode.
Mar 29 10:22:30 ced apsd[89]: APSMessageStore - Enabling Foreign Key support.


##############################################################

Here is PHP code :


##############################################################


$debug = 1;




  $push_apple = 'ssl://gateway.push.apple.com:2195';
  $passphrase = 'XXXX';
  $certificate = 'apns_safari.pem';


  $ctx = stream_context_create();
  if ( $ctx === FALSE ) {
  $error = "Error with stream context";
  if ( $debug ) {
  echo $error.'<br/>'.PHP_EOL;
  }
  } else {
  $stream_success = stream_context_set_option( $ctx, 'ssl', 'local_cert', DIR_FS_CATALOG.'includes/mobile/'.$certificate );
  if ( $stream_success === FALSE ) {
  $error = "Error with stream context option local_cert";
  if ( $debug ) {
  echo $error.'<br/>'.PHP_EOL;
  }
  } else {
  $stream_success = stream_context_set_option( $ctx, 'ssl', 'passphrase', $passphrase );
  if ( $stream_success === FALSE ) {
  $error = "Error with stream context option ssl";
  if ( $debug ) {
  echo $error.'<br/>'.PHP_EOL;
  }
  }
  }
  }


  // Open a connection to the APNS server
  if ( !$error ) {
            $fp = stream_socket_client(
                    $push_apple, $err,
                    $errstr, 60, STREAM_CLIENT_CONNECT | STREAM_CLIENT_PERSISTENT, $ctx );
            if ( $fp === FALSE ) {
                $error = "Failed to connect debug: $err $errstr";
                if ( $debug ) {
                    echo $error.'<br/>'.PHP_EOL;
                }
            } else {

                if ( $debug ) {
                    echo 'Connected to APNS<br/>'.PHP_EOL;
                }
           
                $title = 'toto4';
                $message = 'tata5';
           
                // Create the payload body
                // We are using an intermediary page (last_newsletters.php) to be able
                // to check whether or not the user has read the newsletter.
                $body = array(
                        'aps' => array(
                                'alert' => array(
                                        'title' => $title,
                                        'body' => $message,
                                        'action' => 'viewed',
                                ),
                           
                        ),
                        'url-args' => array('www.spartoo.com'),
                );

                // Encode the payload as JSON
                $payload = json_encode( $body );
           
                $token = '392432F92C7F7A26FC721DD33C53BEB72F3D31A178BE6EA1877F88780008A71B';
                // Build the binary notification
                $msg = chr( 0 ).pack( 'n', 32 ).pack( 'H*', $token ).pack( 'n', strlen( $payload ) ).$payload;
       
                // Send it to the server
                $result = fwrite( $fp, $msg, strlen( $msg ) );
           
                echo $result;
                if ( !$result ) {
                    if ( $debug ) {
                        echo 'Message not delivered (token='.$token.')<br/>'.PHP_EOL;
                    }
                    $invalidDeviceTokens[] = $ios_id;
                } else {
                    if ( $debug ) {
                        echo 'Message successfully delivered (token='.$token.')<br/>'.PHP_EOL;
                    }
                }
               $res = fclose( $fp );
                echo "\nfclose : ".$res;
            }
  }

  if ( $error ) {
  $body = $error;
  $result = '';
  }
  var_dump( $payload);

Hi,

I also like your status.

I think that may be due to outgoing pem file or is there a problem was that push not send.

You have to fix that bug yet?

Hi,


I also facing the same kind of issue. Recieved token. but I am not getting the message in safari ? did you figured it out ?? Please help me if you know what to do..


Thanks,

Safari Push notification never displays
 
 
Q