- coldstart and foreground detection (android and ios)
- callback launched when remote notifification register is done.
- add functions to enable or disable push.
Usage example:
onDeviceReady: function() {
batch.setConfig({"androidAPIKey":"XXXX",
"iOSAPIKey":"XXXX"});
batch.push.setGCMSenderID("XXXX");
batch.start();
batch.push.registerForRemoteNotifications(
function(token) {
alert(token);
},
function() {
alert("cannot get token");
}
);
},
onBatchPush: function(push) {
console.debug("Got a push payload from Batch", push);
if ( push.payload.coldstart == "true" ) {
alert('coldstart');
}
if ( push.payload.foreground == "true" ) {
alert('foreground');
}
if (typeof push.payload.alert !== "undefined") {
alert(push.payload.alert);
}
}
These samples are minimal examples demonstrating a proper integration of the Batch SDK and implementation of Batch Unlock and Batch Push functionality.
-
Clone or download the repository, which contains the SDK and the sample app
-
Go into the BatchSample folder and use standard cordova commands to run the app (ex: "cordova emu ios" or "cordova run android")
1. Login to your Batch.com account or create a new one.
Add a new app on the dashboard using the manual option, as your sample app doesn't have an App Store or Play Store URL to autopopulate.
Within your newly-created app, find the dev API key either here on step 1 of the wizard screen under API KEY
, or in the settings menu under API Keys.
Place the dev API key in your sample app's AppDelegate didFinishStartingWithOptions function, in the startWithAPIKey method call.
At this point, feel free to launch your app. If you select Unlock
, you should see that you haven't yet redeemed any features or items.
Note: The app starts with 10
Lives
, as shown below.
If you are using the wizard, you can now click Test
and should receive a confirmation of your integration if you launched the app with your API key.
The samples are configured with three static items: No Ads
, Pro Trial
, and Lives
.
While the names can vary in the NAME field, the REFERENCE is the case-sensitive value used in the sample code.
No Ads is used to demonstrate restorability. It is recommended to set this to Always restore.
Pro Trial demonstrates a time-to-live (TTL) for expiring offers. Set the option to trial (days) and choose a valid amount of days for the feature to be active.
Lives is an example of a resource, or consumable item. You can define the given quantity in the campaign.
In the campaign screen of your dashboard, create a new Unlock campaign. You can use any of the wizard options, or choose a Custom Offer for manual setup.
As long as the conditions (time, user targeting, URL scheme, capping) match when you launch the app, you will recieve whatever configuration of features and resources you specify. You will also recieve the reward_message
custom parameter, sent as alert, to give feedback to the user about the offer redeemed.
In this example, No Ads
is given in the offer with restore enabled, Pro Trial
is given with a 9 day trial set, and 5 Lives
are given, adding to the previously-mentioned default of 10.
Note: If you set a campaign targeting only new users, ensure that you're running the app for the first time on the device, otherwise it will be considered an existing user. Delete and reinstall to be considered new.
To test the restore functionality, delete the app from your testing device and then reinstall it. Upon relaunch you see that your inventories have been reset to defaults. Within Unlock, select Restore and you will see a confirmation of the restore. Your inventory will now reflect any content you have enabled for restoration.