Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Passing extra data with push notification

    • 0
    • 1
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 511
    Comment on it

    Sometime we do need to send additional data while sending Push-notification on iPhone , this can be easily achieved by adding following line to your code. But one should keep in mind that apple does have a limitation of 144 character while sending a push notification. Thus you notification should not increase the specified limit else the given device wont be receiving the notification :

                       $apnsHost = 'gateway.sandbox.push.apple.com';      
                $apnsPort = 2195;
                $passphrase = 'push'; 
                $streamContext = stream_context_create();
                stream_context_set_option($streamContext, 'ssl', 'local_cert',WWW_ROOT.'ck.pem');        
                stream_context_set_option($streamContext, 'ssl', 'passphrase', $passphrase);
                $apns = stream_socket_client('ssl://gateway.sandbox.push.apple.com:2195' , $error, $errorString, 20, STREAM_CLIENT_CONNECT, $streamContext); 
    
                if (!$apns) {
                    //print "Failed to connect ......... $error $errorString\n"; echo "
    "; } else { $message =""; $data=array(); $message =$senderData['User']['name'].' has shared an event with you start date :'.$albumData['Album']['start_on'].' end data : '.$albumData['Album']['end_on'] ; $data['album_id']=$albumData['Album']['id']; $data['start_on']=$albumData['Album']['start_on']; $data['type']=$albumData['Album']['type']; $data['username']=$senderData['User']['name']; $data['end_on']=$albumData['Album']['end_on']; $payload['aps'] = array('alert' => $message, 'badge' => $notificationCount, 'sound' => 'default'); $payload['server'] = $data; $output = json_encode($payload); $token = pack('H*', str_replace(' ', '', $device_token)); $apnsMessage = chr(0) . chr(0) . chr(32) . $token . chr(0) . chr(strlen($output)) . $output; $result = fwrite($apns, $apnsMessage); } try { socket_close($apns); fclose($apns); } catch(Exception $e) { }

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: