PHP code example of naski / urbanairship-api

1. Go to this page and download the library: Download naski/urbanairship-api library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

naski / urbanairship-api example snippets




rbanAirship\Airship;
use UrbanAirship\AirshipException;
use UrbanAirship\UALog;
use UrbanAirship\Push as P;
use UrbanAirship\Push\MultiPushRequest;
use Monolog\Logger;
use Monolog\Handler\StreamHandler;

UALog::setLogHandlers(array(new StreamHandler("php://stdout", Logger::DEBUG)));

$airship = new Airship("<app key>", "<master secret>");

// Single push
try {
    $response = $airship->push()
        ->setAudience(P\all)
        ->setNotification(P\notification("Hello from php"))
        ->setDeviceTypes(P\all)
        ->send();
} catch (AirshipException $e) {
    print_r($e);
}

// Multi push in single call
try {
    $multiPushRequest = new MultiPushRequest($airship);
    $multiPushRequest->addPushRequest(
        $airship->push()
            ->setAudience(P\all)
            ->setNotification(P\notification("Hello from php"))
            ->setDeviceTypes(P\all)
    );
    $response = $multiPushRequest->send();
} catch (AirshipException $e) {
    print_r($e);
}