PHP code example of level51 / silverstripe-onesignal

1. Go to this page and download the library: Download level51/silverstripe-onesignal 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/ */

    

level51 / silverstripe-onesignal example snippets


try {
    $notification = Notification::create()
        ->addHeading('en', 'My first notification')
        ->addContent('en', 'Yay, my Silverstripe app created this')
        ->addData('myVar', 'foo');

    $response = OneSignalService::singleton()->createNotification($notification);
    if (!$response->isError()) {
        echo 'Notification with id ' . $response->getId() . ' was sent to ' . $response->getRecipientsCount() . ' recipients';
    }
} catch (OneSignalException $e) {}