BlackBerry 10 Cascades

**Download SDK **Download Sample

The SDK contains the source code for BlackBerry 10 Cascades platform, please download it from our repo first.

Enlist which libraries must be defined into the .pro file to avoid compilation error:

LIBS += -lbb LIBS += -lbbdevice LIBS += -lbbsystem LIBS += -lbbnetwork LIBS += -lbbplatform LIBS += -lbbdata
**IMPORTANT:** For **push evaluation** the PPG_URL should use http:// scheme, not https:// `#define PPG_URL "http://pushapi.eval.blackberry.com”`
**1.** In your main App add push notifications service:
PushNotificationService m_pushNotificationService;
**2.** Initialize push service:
m_pushNotificationService.initializePushService(BLACKBERRY_APPID, PPG_URL, PUSHWOOSH_APP_ID, INVOKE_TARGET_KEY_PUSH, INVOKE_TARGET_KEY_OPEN);
Note that **INVOKE_TARGET_KEY_PUSH** needs to match the invoke target specified in **bar-descriptor.xml**. For example, this is Invoke target key for receiving new push notifications:

com.pushwoosh.example.invoke.push

Note that INVOKE_TARGET_KEY_OPEN needs to match the invoke target specified in bar-descriptor.xml. For example, this is Invoke target key when selecting a notification in the BlackBerry Hub:

com.pushwoosh.example.invoke.open

3. Connect the push notification service signals and slots:

QObject::connect(&m_pushNotificationService, SIGNAL(registeredForPushNotifications(const QString &)), this, SLOT(registeredForPushNotifications(const QString &))); QObject::connect(&m_pushNotificationService, SIGNAL(errorRegisteringForPushNotifications(const QString &)), this, SLOT(errorRegisteringForPushNotifications(const QString &)));
Example of callback functions:
void App::registeredForPushNotifications(const QString & token) { qDebug() << "subscribed for push with token: " << token; } void App::errorRegisteringForPushNotifications(const QString & error) { qDebug() << "error subscribing for push: " << error; } [/sourcecode]

4. Initialize push session:

m_pushNotificationService.createSession();
**5.** Subscribe for push notifications:
m_pushNotificationService.registerForPushNotifications();
**6.** Handle push notifications:
void App::onInvoked(const InvokeRequest &request) { if (request.action().compare(BB_PUSH_INVOCATION_ACTION) == 0) { qDebug() << "Received push action"; // Received an incoming push // Extract it from the invoke request and then process it PushPayload payload(request); if (payload.isValid()) { //call pushwoosh handler for stats etc. m_pushNotificationService.pushNotificationHandler(pushPayload); //handle push } } else if (request.action().compare(BB_OPEN_INVOCATION_ACTION) == 0){ qDebug() << "Received open action"; // Received an invoke request to open an existing push (ie. from a notification in the BlackBerry Hub) // The payload from the open invoke is the seqnum for the push in the database // Process opened push here } } [/sourcecode]

7. In bar-description.xml add permissions for push and device info:

_sys_use_consumer_push read_device_identifying_information post_notification
**8.** Also add Invoke actions:
APPLICATION bb.action.PUSH application/vnd.push APPLICATION bb.action.OPEN text/plain
That’s it, now the application should be able to subscribe a device to receive push notifications, and receive them properly.

Get/Set tags:

Include necessary headers:

#include "pushwoosh/request/PWRequest.h" #include "pushwoosh/request/PWSetTagsRequest.h" #include "pushwoosh/request/PWGetTagsRequest.h"
Define callback SLOTS:
void App::setTagsFinished(PWRequest * request) { if(!request->isValid()) { QString error = request->getError(); qDebug() << "Set Tags Error: " << error; return; } qDebug() << "Set Tags Success"; } void App::getTagsFinished(PWRequest * request) { if(!request->isValid()) { QString error = request->getError(); qDebug() << "Get Tags Error: " << error; return; } PWGetTagsRequest * req = (PWGetTagsRequest *) request; QVariantMap tags = req->getTags(); QString reqString; bb::data::JsonDataAccess jda; jda.saveToBuffer(tags, &reqString); qDebug() << "Get Tags Success: " << reqString; } [/sourcecode]

To set tags call:

QVariantMap map; map["Hello"] = 5; map["String"] = "Value"; QList array; array.push_back(QString("One")); array.push_back(QString("Two")); map["Array"] = QVariant(array); m_pushNotificationService.setTags(map, this, SLOT(setTagsFinished(PWRequest*)));
To get tags call:
m_pushNotificationService.getTags(this, SLOT(getTagsFinished(PWRequest*)));