Skip to main content

Apple Push Notification service (APNs) - for notifying iphone app users about latest and interesting things happening even if they are not using App

Apple Push Notification service

There are thousands of applications available for iphone and android devices. Here we will be discussing about the Apple Push Notification service which helps to alert user of an iphone application about new data from Application provider. Suppose an Online magazine website is providing an iphone app to it users, where they can browse their magazine and download it their iphone. When a new online edition is uploaded, the website will trigger the Notification service to send message / notification to its iphone app users related to availablity of new edition. So that they are informed about latest updates on the site.

Apple Push Notification service transports and routes a notification from a given provider to a given device. Here what happens is , when an app is installed on iphone, it asks whether user wish to get push notifications, If user confirms then a device token is generated for that device and it is send to the app provider's server and there the device token is saved for future notify process. When a new or interesting thing happens on the site, the Service provider (may be a Website) send notification to Apple Push Notification Server (APNS). A notification is a short message consisting of two major pieces of data: the device token and the payload. The device token is analogous to a phone number; it contains information that enables APNs to locate the device on which the client application is installed. The server identifies the device and send notification to the device (iphone) and the device passes the notification to the installed App. The payload is a JSON-defined property list that specifies how the user of an application on a device is to be alerted.

There are three things a push notification can do ( This is passed to APNs as JSON payload):
Display a text message as an alert
Play a brief sound
Set a number in a badge on the app’s icon

When the user’s device receives the push notification, it shows an alert, plays a sound and/or updates the app’s icon. The user can launch the app from the alert. The contents of the push notification can be passed to the app where it can be used as needed.

On the Providers website You can use a server side script like PHP to connect to Apple Push Notification Server and send the notification data having device token and Payload.

Sample PHP script to connect o APN server


$apns_link="ssl://gateway.push.apple.com:2195"; //live apn server
//$apns_link="ssl://gateway.sandbox.push.apple.com:2195"; //test apn server

$pem_file="cp.pem";
$passphrase="YOUR_PASSPHRASE";
$deviceToken="740d89jmbebcf74f9b7c25d48e335894f5f6aa01da5hddb387462c7reaf61bb78ad";
$message="New Magazine uploaded, please check";

$ctx = stream_context_create();

//stream_context_set_option($ctx, 'ssl', 'local_cert', 'ck.pem');
stream_context_set_option($ctx, 'ssl', 'local_cert', $pem_file );

stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);

// Open a connection to the APNS server
$fp = stream_socket_client($apns_link, $err, $errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);

// checkinging for connection establishment
if (!$fp)
exit("Failed to connect to APN Server: $err $errstr" . PHP_EOL);

echo 'Connected to APN Server.' . PHP_EOL;

// Create the payload body
$body['aps'] = array(
'alert' => $message,
'badge' => 1,
'sound' => 'default'
);

// Encode the payload as JSON
$payload = json_encode($body);

// Build the binary notification
$msg = chr(0) . pack('n', 32) . pack('H*', $deviceToken) . pack('n', strlen($payload)) . $payload;

// Send it to the server
$result = fwrite($fp, $msg, strlen($msg));

if (!$result)
echo "Message not delivered. " . PHP_EOL;
else
echo "Message successfully delivered" . PHP_EOL;

fclose($fp);


for more info, please refer

APPLE PUSH NOTIFICATION SERVICE VIDEO TUTORIALS

www.developer.apple.com
www.raywenderlich.com

Comments

Popular posts from this blog

How to apply for a new ration card and what are the documents required?

List of documents required for new ration card application in Kerala and how to apply


Application for a new ration card should be addressed to Taluk Supply Officer (TSO) / City Rationing Officer (CRO) of applicant's residing area.

Primary document required are Residence certificate, Income certificate and incase the applicant's name is in another ration card then he/she should submit the reduction certificate ontained from previous TSO / CRO as proof for removing his/her name from old Ration card.

You can get the new application from your currently residing Taluk Supply Office.

Payback Points - How to redeem - How to merge multiple payback accounts - Block Payback card - Payback customer care

Joomla and Forum Integration - Integrating Forums to Joomla

Joomla is one of the most popular CMS opensource packages. It is very easier to develop website's using Joomla. You just need to download Joomla package from Joomla's Official website www.joomla.org  and install it on your domain and later adding customizations to templates and feature and Your website is ready :). Now a days most websites provides a forum section for it users for discussing various article topics, gathering opinions etc.



Following are some best know forum opensource packages which can be integrated with Joomla and create a new forum experience for users


Urgent Openings for PHP trainees, Andriod / IOS developers and PHP developers in Kochi Trivandrum Calicut and Bangalore. Please Send Your updated resumes to recruit.vo@gmail.com   Read more »
Member
Search This Blog