A PHP Library for Apple Push Notification Service
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
src/apns
LICENSE
README.md
composer.json

README.md

Apple Push Notification Service via PHP

A PHP Library for Apple Push Notification Service

Features

  • Send Push Notification
  • Customise as JSON Payload

Pre-requisite

  1. Device Token which you will get as callback (in AppDelegate.swift) when you register for Push Notification.
  2. PEM Certificate of your app which you get from Apple Developer Portal.

Installation

You can install apnsPHP via Composer. First, add composer.json file in your project

{
  "require": {
    	"apns/apnsPHP": "*"
    }
}

And, install dependencies by command

composer install

Code

  1. Send Push Notification when you've text only

I'm assuming you have pem certificate with you.


//Path of Certfiicate
$pathOfCertificate = $_SERVER['DOCUMENT_ROOT']."/certificate.pem";

// Initialise APNS
$apns = new apnsPHP($pathOfCertificate);
$apns->sendPushNotification("This is my Message", $token);
  1. Send Push Notification when you've complete JSON Payload

As, Apple Push Notification payload looks like this where, alert is the push-notification message, badge is the badge number which comes on AppIcon in numeric form with red bubble and last is sound which is alert tone when push notification pops.

{
  "aps":{
    "alert" : "Hello World :D",
    "badge" : 1,
    "sound" : "default"
  }
}

So, you have to first prepare the payload and then call apns defined method,

// Token
$token = "FCFFA7C61D647BA62DAxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";

// Associative Array
$payload['aps'] = array('alert' => 'Hello World :D', 'badge' => 1, 'sound' => 'default');

// Convert Array into JSON
$payloadJSON = json_encode($payload);

And, last you have to call APNS method.


$apns = new apnsPHP($pathOfCertificate);
$apns->sendPushNotification($payloadJSON, $token);

Reference

You can refer Apple Documentation for Apple Push Notification Service.