All functions take single argument, object with properties recognized by each individual API point entry. Those functions will throw error when one or more of required parameters are missing. All result will be delivered asynchronously, by executing callback functions passed as arguments to API calls.
Arguments to all API calls can have ios: {...}
or android: {...}
sections, values
specified that way would overwrite general data from adequate platform section.
Before any other operation can be performed, Boxcar API must be
initialized, this is performed by calling Boxcar.init()
.
After that application can register retrieve list of tags by using Boxcar.getTags()
or skip that step if interesting tags are already known.
To make device receive push notificaitons Boxcar.registerDevice()
must be called, after
that all new notificaitons are delivered to applications by executing onalert
callback
provided in that API call
Make sure that on machine where build will be performed [Apache Cordova][http://cordova.apache.org/], and Android or/and IOS SDK installed.
As first step, we need to create new cordova project using: cordova create /path/to/our-project our.domain.testapp1 "Test Applicaton"
After that we need to switch to app directory: cd /path/to/our-project
Next we need to declare for what platforms we want build our application: cordova platform add android cordova platform add ios
Then we need to download plugins required by Boxcar SDK cordova plugin add org.apache.cordova.device cordova plugin add https://github.com/boxcar/PushPlugin
On android Storage API used by SDK needs to be enabled manaully in one of config files.
To do that XML file platform/android/res/xml/config.xml
must have additional clause
directly in <widget>
element.
After that we need put our program files together with Boxcar.js
file in www/ directory.
We also need to include Boxcar.js
and PushNotification.js
file in our index.html
file.
<script type="text/javascript" charset="utf-8" src="PushNotification.js"></script>
<script type="text/javascript" charset="utf-8" src="Boxcar.js"></script>
Packages for iOS platform can be only build with Xcode IDE, executing cordova prepare ios
will fill platform/ios
directory which can be opened in Xcode.
Developing for Android can also be done using IDE environment, first by preparing build directory: cordova prepare android
and then creating IDE project from platfrom/android
directory, but this can also be performed from
CLI by executing
cordova build android
to build APK file, and calling cordova run android
to install and start application on Android device.
This method initializes internal structures, and archived notifications database
Arguments:
clientKey
(required) - Key used to access service,secret
- (required) - Secret value needed to access serviceserver
- (required) - Url of push bridge serverandroidSenderID
- (required, android only) - Project number assigned to your application in Google Developers ConsolerichUrlBase
- (required) - Url of server where html content of received pushes are available
This method register device in push service, making it be able to receive new pushes
Arguments:
mode
(required) - String with "production" or "development" telling push service if production or development delivery channel should be used to register this deviceonsuccess
(required) - Calback function called when device was successfully registered in push serviceonerror
(required) - Callback function called when device registration was unsuccessful, it receives single String value is error descriptiononalert
(required) - Callback function called when new push message was received, it receive object with properties initialized from notificaiton contentonnotificationclick
(required) - Callback function called when user clicked on notification ui generated from push. This event can be dispatched only for pushes received when app was in background, as for pushes received when app was active notification is not displayed. This function is called with single object argument with properties initialized from notificaiton contenttags
- List of strings with tags used to filter which notifications should be deliveredudid
- Unique identifier of device where application is runalias
- Friendly name of device where application is runappVersion
- String with version of your application
Objects passed to onalert
and onnotificationclick
callbacks have those fields:
id
- unique identifier of push notificationtime
- time in miliseconds since epoch of when this message was received, this value can be converted to Date object by callingnew Date(msg.time)
sound
- string identifer of sound which should be played with notificationbadge
- number of unread messages on serverbody
- body of push notificationrichPush
- boolean value telling if this push includes html formated contenturl
- url to html content include in this pushseen
- boolean value telling ifmarkAsReceived
was used for this push notification idextras
- object containing values defined as "Extra Variables" in push console
Unregister device from push notifications
Arguments:
onsuccess
(required) - Callback function called when operation was successfully completedonerror
(required) - Callback function, it's called when error happen, receivessingle String with error message
This method retrieves list of tags assigned to push notification channel from server
Arguments:
onsuccess
(required) - Callback function called when list of tags was retrieved, it receives one argument, list of strings with all tags assigned on serveronerror
(required) - Callback function, it's called on error with single String with error message
Inform push service that push message was seen by user. This also makes message info returned
for further Boxcar.getReceivedMessages()
to have seen
attribute set to true
Arguments:
onsuccess
(required) - Callback function called when operation was successfully completedonerror
(required) - Callback function, it's called when error happen, receivessingle String with error messageid
(required) - String identifier of push notification to mark as received
Reset count of notificaitons to zero
Arguments:
onsuccess
(required) - Callback function called when operation was successfully completedonerror
(required) - Callback function, it's called when error happen, receivessingle String with error message
Retrieves list of received messages from device storage. Messages are delivered from newest to oldest.
Arguments:
onsuccess
(required) - Callback function called when operation was successfully completed, this function receives single argument with list of notifications object described inBoxcar.registerDevice()
onerror
(required) - Callback function, it's called when error happen, receivessingle String with error messagebefore
- Number with timestamp, it will make this function return only messages newer than date from timestamplimit
- Maximum number of messages which should be returned