Sencha Touch with GameThrive.com

Montag, 17. November 2014
Hey Touchers,

some of you might know GameThrive.com. For those who don't: it's a completly free push notification service. This weekend GaemThrive published a guide for Phonegap. I had to apply some changes so it's working with Sencha. This is how you will get GameThrive working with Sencha Touch:

1. Install the external preconditions from step 1 and / or 2 HERE

2. Add the following plugins.
// Phonegap
phonegap plugin add org.apache.cordova.device
phonegap plugin add https://github.com/GameThrive/GameThrive-PhoneGap-SDK
// Cordova
cordova plugin add org.apache.cordova.device
cordova plugin add https://github.com/GameThrive/GameThrive-PhoneGap-SDK

3. Add this to your launch function and replace the app_id (iOS) or senderId(Android) in the jsonData Object:
var gameThrive = window.plugins.GameThrive;
if (device.platform == "Android") {
gameThrive.register(successHandler, errorHandler,{"senderID":"703322744261","ecb":"onNotificationGCM"});
}
else if (device.platform == "iOS") {
gameThrive.register(
tokenHandler,
errorHandler,
{
"badge":"true",
"sound":"true",
"alert":"true",
"ecb":"onNotificationAPN"
});
}
function successHandler(result) {
}
function errorHandler(error) {
}
function tokenHandler(pushToken) {
sendPushToken(pushToken);
}
function onNotificationGCM(e) {
switch( e.event ) {
case 'registered':
if ( e.regid.length > 0 ) {
sendPushToken(e.regid);
}
break;
case 'message':
alert('message = ' + e.alert);
break;
case 'error':
console.log('GCM error = ' + e.msg);
break;
default:
console.log("Unknown GCM event: " + e.event);
break;
}
}
function sendPushToken(pushToken) {
var playerId = window.localStorage.getItem("playerId");
var device_type = (device.platform == "Android" ? 1 : 0);
var sendURL;
if (playerId === null) {
sendURL = "https://gamethrive.com/api/v1/players";
}
else {
sendURL = "https://gamethrive.com/api/v1/players/" + playerId + "/on_session";
}
var jsonData = {
app_id: "ad797c16-6e38-11e4-a458-ab7492be584b",
device_type: device_type,
identifier: pushToken,
timezone: (new Date()).getTimezoneOffset() * -60
};
Ext.Ajax.request({
type: "POST",
dataType: "json",
url: sendURL,
jsonData: jsonData,
success: function(response) {
window.localStorage.setItem("playerId", response.id);
console.log("Device registered with GameThrive!");
},
error: function (e) {
console.log("Device failed registering with GameThrive: " + e);
}
});
}
view raw launch.js hosted with ❤ by GitHub



This is it. You will find a full Sencha Architect example to download HERE.

Questions and improvements are welcome!


Source:
http://documentation.gamethrive.com/v1.0/docs/phonegap-sdk-installation

Keine Kommentare:

Kommentar veröffentlichen