Add push notifications for Android and iOS mobile apps

Space-O Technologies
Published on Jun 14, 2016 in App Development
Add push notifications for Android and iOS mobile apps-Space-O

Push notifications have a high engagement rate, just like click-through rates. Push notifications are a type of message that is sent from an app to a device. Usually, it is used in mobile apps to deliver relevant information to users. Push notifications appear as alert messages or in a notification area at the top of the device’s screen.

iOS and Android programming languages provide their own push notifications service mechanism, but developers are looking for some more powerful push notifications services and thus. Space-O is aware of that, that's why they provide their own solution.

There is around four third-party push notifications services available in the market that are used in iOS APNs and Android GSM. Among all, the variable is the best to provide your own device token and use your own mechanism to send a push notification. It is an Urban airship.

How to implement Urban airship API in PHP? There are not good documents for support, so here Space-O suggests you the steps to easily integrate in PHP.

  • Create an app in Urban airship
  • Get API credential from Urban airship for a particular app
  • Get API Key, App Secret Key, App master Secret Key
  • Apply all in Urban Airship Class in constructor
  • Test push Notification from Urban airship
  • Get Payload form Urban airship which you send testing push
  • Set it in our Urban airship class and check it

Rules of Urban airship API integration

  • iOS: device token pass with key name of "device_token"

    Android: device token pass with key name of "android_channel"

  • iOS: badge and sound and alert are default parameter.

    Android: only one default parameter.

Example for Push Send for Android

class Urban_airship {
private $key;
private $secret;
private $mastersecret;
public function __construct()
{

// >>> get form urban airship section of APIs & Integrations

$this -> key = 'G7PXHwfJQXCinyPKCqglcw';
$this -> secret = 'RVw68AWnSQuc7p4jIm8Dbw';
$this -> mastersecret = 'gnOGDnZDRLuqc0wTg6M7sg';
}
private function _send($method, $url, $payload = null){
$session = curl_init('https://go.urbanairship.com/' . $url);
if($payload !== null){
$payload = json_encode($payload);
curl_setopt($session, CURLOPT_POSTFIELDS, $payload);
curl_setopt($session, CURLOPT_HTTPHEADER, array('Content-Type:application/json', 'Accept: application/vnd.urbanairship+json; version=3;'));
}
switch ($method) {
case 0:
curl_setopt($session, CURLOPT_USERPWD, 'G7PXHwfJQXCinyPKCqglcw:gnOGDnZDRLuqc0wTg6M7sg');
curl_setopt($session, CURLOPT_POST, True);
break;

case 1:

curl_setopt($session, CURLOPT_USERPWD, 'G7PXHwfJQXCinyPKCqglcw:gnOGDnZDRLuqc0wTg6M7sg');
curl_setopt($session, CURLOPT_CUSTOMREQUEST, 'PUT');
break;
}
curl_setopt($session, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($session, CURLOPT_HEADER, False);
curl_setopt($session, CURLOPT_RETURNTRANSFER, True);
curl_exec($session);
$response = curl_getinfo($session);

curl_close($session);
return $response['http_code'];
}
public function push($tokens, $aps)
{

//$aps['badge'] = isset($aps['badge']) ? $aps['badge'] : '';
$aps['alert'] = isset($aps['alert']) ? $aps['alert'] : '';

//$aps['extra']['type'] = isset($aps['type']) ? $aps['type'] : '';
//$aps['extra']['itemId'] = isset($aps['itemId']) ? $aps['itemId'] : '';

// $extra['type'] = $aps['type'];
// $extra['itemId']= $aps['itemId'];

//unset($aps['type']);
//unset($aps['itemId']);
$notification = array();
$notification = $aps;
$platform = array();
array_push($platform, "android");
$devices = array();
array_push($devices,array('android_channel' => $tokens));
//array('device_token' => $tokens)
$audience = array('or' =>$devices );
$push = array("audience"=>$audience, "notification"=>$notification, "device_types"=>$platform);

$json = json_encode($push);

$session = curl_init('https://go.urbanairship.com/api/push/');
curl_setopt($session, CURLOPT_USERPWD, 'G7PXHwfJQXCinyPKCqglcw:gnOGDnZDRLuqc0wTg6M7sg');
curl_setopt($session, CURLOPT_POST, True);
curl_setopt($session, CURLOPT_POSTFIELDS, $json);
curl_setopt($session, CURLOPT_HEADER, False);
curl_setopt($session, CURLOPT_RETURNTRANSFER, True);
curl_setopt($session, CURLOPT_HTTPHEADER, array('Content-Type:application/json', 'Accept: application/vnd.urbanairship+json; version=3;'));
$content = curl_exec($session);
echo "Response: " . $content . "\n";
die();
// Check if any error occured
$response = curl_getinfo($session);
if($response['http_code'] != 202) {
echo "Got negative response from server: " . $response['http_code'] . "\n";
} else {
echo "Wow, it worked!\n";
}
curl_close($session);
}
}
// End of urban airship class
Example of Push send file

'; // it take from android app.

$aps = array(
'alert' => $message,
);

// Send the push notification
$http_code = urban_airship::push($tokens, $aps);

?>

Involver-Social Volunteering app allows users to search great volunteering events from hundreds of communities nearby them. Users have to choose three causes based on categories you like the most. Users will get a notification about events and opportunities provided to them.

Fitnus is another fitness app that allows users to meet new people through activities and sports. Fitnus app has an easy way to search and pick games and other activities created by the people. Having push notification functionality, it lets others know you’re ready to play. This application also has popular sports and activities like Gym Workouts, Gym Classes, Volleyball, Running, Football, Basketball, Yoga, Softball, and many others.

The experienced mobile app development team of Space-O integrates push notification in any app type.

As you can see, push notifications are key for the success of your app. People use their smartphones thousands of times every day, they download apps that after one use, they might forgot about them. So mobile app development companies have to be aware of the importance of the push notifications to remind the users that they have your mobile app installed and need to use it to find the best restaurante, the perfect match, the best trip price or the top boutique.

Looking for an app or software development company?

You can post a project on AppFutura for free and explain your needs for app or software development. You will receive quotes from qualified companies and will be able to hire the best candidate through a safe payment system.

Post a project

About the author
Space-O Technologies
Space-O Technologies
ContactVisit website

We have expertise in design & development of 200+ apps for iPhone, iPad and Android Applications using Native iOS SDK, Android, Hybrid app development, iWatch, Watch Kit, Health Kit

You might also like