Skip to content

An easy to use Apple Push Notification Service wrapper for PHP applications.

License

Notifications You must be signed in to change notification settings

hallewood/apns-sdk-php

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Apple Push Notification Service (PHP-SDK)

Send a notification

use Hallewood\APNS\ApplicationBundle;
use Hallewood\APNS\Notification;

//
// Define bundle identifier, team id, key id and path to the private key file
ApplicationBundle::shared('com.bundle.identifier', 'ABC7890', 'K1234567', '/path/to/key/file.p8');

(new Notification())
	->title('Hello, world!')
	->body('My very first notification')
	->sound('default', true)
	->push('ec0aebfb4ec465e294c2afaf291cb3e4df5aeee934ed11fbdad7258724336896');

Send a notification to multiple devices:

$deviceTokens = ['token-1', 'token-2', 'token-3'];

$notificationForAll = (new Notification())
	->title('Hello, world!')
	->body('My very first notification')
	->sound('default', true);

//
// Prepare notifications for specific device tokens
$notificationForAll->push($deviceTokens, function (Notification $notification, string $deviceToken) {
	if ($deviceToken == 'token-2') {

		//
		// The second device token receives an additional subtitle
		$notification->subtitle('You are the second to receive a notification');
	}

	return $notification;
});

Send a notification to multiple apps:

use Hallewood\APNS\ApplicationBundle;
use Hallewood\APNS\Notification;
use Hallewood\APNS\Dispatcher;
use Hallewood\APNS\Dispatch\DispatchUnit;

$firstAppBundle  = new ApplicationBundle('com.developer.first-app', 'ABC7890', 'K1234567', '/path/to/key/file.p8');
$secondAppBundle = new ApplicationBundle('com.developer.second-app', 'ABC7890', 'K1234567', '/path/to/key/file.p8');

$notification = (new Notification())
	->title('Hello, world!')
	->body('This is a notification received by multiple apps')
	->sound('default', true)

$dispatcher = new Dispatcher();
$dispatcher
	->addDispatchUnit(new DispatchUnit($notification, ['token-1', 'token-2', 'token-3'], $firstAppBundle))
	->addDispatchUnit(new DispatchUnit($notification, ['token-4', 'token-5', 'token-6'], $secondAppBundle))
	->push();

About

An easy to use Apple Push Notification Service wrapper for PHP applications.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages