Code Monkey home page Code Monkey logo

mano-mykingdom.tipush's Introduction

TiPush

Description

GCM Push support for android.

Usage

var TiPush = require("ti.push");
TiPush.addEventListener("callback", function(e) {
	console.log("callback fired");
	//test parsing
	var data = JSON.parse(e.payload);
	label.text = JSON.stringify(data);
});

var isAvailable = TiPush.isGooglePlayServicesAvailable();
switch (isAvailable) {
case TiPush.SERVICE_DISABLED:
	Ti.API.info("SERVICE_DISABLED");
	break;
case TiPush.SERVICE_INVALID:
	Ti.API.info("SERVICE_INVALID");
	break;
case TiPush.SERVICE_MISSING:
	Ti.API.info("SERVICE_MISSING");
	break;
case TiPush.SERVICE_UPDATING:
	Ti.API.info("SERVICE_UPDATING");
	break;
case TiPush.SERVICE_VERSION_UPDATE_REQUIRED:
	Ti.API.info("SERVICE_VERSION_UPDATE_REQUIRED");
	break;
case TiPush.SUCCESS:
	Ti.API.info("SUCCESS");
	break;
default:
	Ti.API.info("Something went wrong, no matches : " + isAvailable);
}

var window = Ti.UI.createWindow({
	backgroundColor : "#FFFFFF"
});
window.open();

var scrollView = Ti.UI.createScrollView({
	layout : "vertical"
});
window.add(scrollView);

var deviceIdBtn = Ti.UI.createButton({
	title : "Get device id",
	top : "20"
});
deviceIdBtn.addEventListener("click", getDeviceId);
scrollView.add(deviceIdBtn);

var registerBtn = Ti.UI.createButton({
	title : "Register",
	top : "20"
});
registerBtn.addEventListener("click", getToken);
scrollView.add(registerBtn);

var unregisterBtn = Ti.UI.createButton({
	title : "Un-Register",
	top : "20"
});
unregisterBtn.addEventListener("click", deleteToken);
scrollView.add(unregisterBtn);

var updateBtn = Ti.UI.createButton({
	title : "Update",
	top : "20"
});
updateBtn.addEventListener("click", update);
scrollView.add(updateBtn);

var newWinBtn = Ti.UI.createButton({
	title : "Open new window",
	top : "20"
});
newWinBtn.addEventListener("click", openNewWin);
scrollView.add(newWinBtn);

var label = Ti.UI.createLabel({
	top : 20,
	left : 12,
	right : 12,
	textAlign : "center",
	color : "#000"
});
scrollView.add(label);

function getDeviceId() {
	alert(TiPush.deviceId);
}

function update() {
	TiPush.updateGooglePlayServices();
}

function getToken() {
	TiPush.retrieveDeviceToken({
		senderId : "15063256342",
		success : function(evt) {
			console.log(evt);
		},
		error : function(evt) {
			console.log(evt);
		}
	});
}

function deleteToken() {
	TiPush.clearStatus({
		senderId : "15063256342",
		success : function(evt) {
			console.log(evt);
		},
		error : function(evt) {
			console.log(evt);
		}
	});
}

function openNewWin() {
	Ti.UI.createWindow({
		backgroundColor : "#FFFFFF"
	}).open();
}

mano-mykingdom.tipush's People

Contributors

manojdcoder avatar

Watchers

Brenton House avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.