jpush-phonegap-plugin/www/JPushPlugin.js

206 lines
4.9 KiB
JavaScript
Raw Normal View History

2014-06-05 16:36:54 +08:00
var JPushPlugin = function(){
};
2014-06-10 14:54:17 +08:00
JPushPlugin.prototype.isPlatformIOS = function(){
return device.platform == "iPhone" || device.platform == "iPad" || device.platform == "iPod touch" || device.platform == "iOS"
}
2014-06-10 14:14:02 +08:00
JPushPlugin.prototype.error_callback = function(msg){
console.log("Javascript Callback Error: " + msg)
2014-06-05 16:36:54 +08:00
}
2014-06-12 11:02:33 +08:00
JPushPlugin.prototype.call_native = function(name, args, callback){
2014-06-12 15:08:19 +08:00
ret = cordova.exec(callback,this.error_callback,'JPushPlugin',name,args);
2014-06-10 14:14:02 +08:00
return ret;
2014-06-05 16:36:54 +08:00
}
2014-06-12 14:39:46 +08:00
JPushPlugin.prototype.startLogPageView = function(data){
if(this.isPlatformIOS()){
this.call_native( "startLogPageView",[data],null);
}
2014-06-10 14:14:02 +08:00
}
2014-06-05 16:36:54 +08:00
2014-06-10 14:14:02 +08:00
JPushPlugin.prototype.stopLogPageView = function(data){
2014-06-12 14:39:46 +08:00
if(this.isPlatformIOS()){
this.call_native( "stopLogPageView",[data],null);
}
2014-06-05 16:36:54 +08:00
}
2014-06-04 13:20:24 +08:00
2014-06-10 14:14:02 +08:00
JPushPlugin.prototype.setTagsWithAlias = function(tags,alias){
2014-06-12 11:02:33 +08:00
try{
if(tags==null){
this.setAlias(alias);
return;
}
if(alias==null){
this.setTags(tags);
return;
}
var arrayTagWithAlias=[tags];
arrayTagWithAlias.unshift(alias);
this.call_native( "setTagsWithAlias", arrayTagWithAlias,null);
2014-06-10 14:14:02 +08:00
}
2014-06-12 11:02:33 +08:00
catch(exception){
console.log(exception);
}
2014-01-20 18:27:31 +08:00
}
2014-06-10 14:14:02 +08:00
2014-06-12 11:02:33 +08:00
JPushPlugin.prototype.getRegistrationID = function(callback){
try{
var data=[];
this.call_native("getRegistrationID",[data],callback);
}
catch(exception){
console.log(exception);
}
}
2014-06-10 14:14:02 +08:00
JPushPlugin.prototype.setTags = function(data){
2014-01-20 18:27:31 +08:00
2014-06-10 14:14:02 +08:00
try{
2014-06-12 11:02:33 +08:00
this.call_native("setTags",data,null);
2014-06-10 14:14:02 +08:00
}
catch(exception){
console.log(exception);
}
2014-01-20 18:27:31 +08:00
}
2014-06-10 14:14:02 +08:00
JPushPlugin.prototype.setAlias = function(data){
try{
2014-06-12 11:02:33 +08:00
this.call_native("setAlias",[data],null);
2014-06-10 14:14:02 +08:00
}
catch(exception){
console.log(exception);
}
2013-10-18 11:14:33 +08:00
}
2014-06-10 14:14:02 +08:00
2014-07-22 20:14:01 +08:00
JPushPlugin.prototype.receiveMessageIniOSCallback = function(data){
2014-06-10 14:14:02 +08:00
try{
2014-07-22 20:14:01 +08:00
console.log("JPushPlugin:receiveMessageIniOSCallback--data:"+data);
2014-07-22 18:51:48 +08:00
var bToObj = JSON.parse(data);
var content = bToObj.content;
console.log(content);
}
catch(exception){
2014-07-22 20:14:01 +08:00
console.log("JPushPlugin:receiveMessageIniOSCallback"+exception);
}
}
2014-07-23 14:46:02 +08:00
JPushPlugin.prototype.receiveMessageInAndroidCallback = function(data){
try{
console.log("JPushPlugin:receiveMessageInAndroidCallback");
console.log(data);
//var bToObj=JSON.parse(data);
//var message = bToObj.message;
//var extras = bToObj.extras;
2014-07-23 14:46:02 +08:00
//console.log(message);
//console.log(extras['cn.jpush.android.MSG_ID']);
//console.log(extras['cn.jpush.android.CONTENT_TYPE']);
//console.log(extras['cn.jpush.android.EXTRA']);
2014-07-23 14:46:02 +08:00
}
catch(exception){
console.log("JPushPlugin:pushCallback "+exception);
}
}
//
2014-07-22 18:51:48 +08:00
JPushPlugin.prototype.openNotificationInAndroidCallback = function(data){
try{
console.log("JPushPlugin:openNotificationInAndroidCallback");
console.log(data);
//var bToObj = JSON.parse(data);
//var alert = bToObj.alert;
//var extras = bToObj.extras;
//console.log(alert);
//console.log(extras['cn.jpush.android.MSG_ID']);
//console.log(extras['app']);
//console.log(extras['cn.jpush.android.NOTIFICATION_CONTENT_TITLE']);
//console.log(extras['cn.jpush.android.EXTRA']);
//console.log(extras['cn.jpush.android.PUSH_ID']);
//console.log(extras['cn.jpush.android.NOTIFICATION_ID']);
//console.log("JPushPlugin:openNotificationCallback is ready");
2014-06-10 14:14:02 +08:00
}
catch(exception){
console.log(exception);
}
2013-10-21 11:28:42 +08:00
}
2014-06-12 14:39:46 +08:00
//android single
JPushPlugin.prototype.setBasicPushNotificationBuilder = function(){
if(device.platform == "Android") {
data=[]
this.call_native("setBasicPushNotificationBuilder",data,null);
}
}
JPushPlugin.prototype.setCustomPushNotificationBuilder = function(){
if(device.platform == "Android") {
data=[];
this.call_native("setCustomPushNotificationBuilder",data,null);
}
}
JPushPlugin.prototype.stopPush = function(){
if(device.platform == "Android") {
data=[];
this.call_native("stopPush",data,null);
}
}
JPushPlugin.prototype.resumePush = function(){
if(device.platform == "Android") {
data=[]
this.call_native("resumePush",data,null);
}
}
2014-07-22 20:14:01 +08:00
JPushPlugin.prototype.clearAllNotification = function(){
2014-06-12 14:39:46 +08:00
if(device.platform == "Android") {
data=[]
this.call_native("clearAllNotification",data,null);
}
}
JPushPlugin.prototype.setLatestNotificationNum = function(num){
if(device.platform == "Android") {
this.call_native("setLatestNotificationNum",[num],null);
}
}
JPushPlugin.prototype.isPushStopped = function(callback){
if(device.platform == "Android") {
data=[];
this.call_native("isPushStopped",data,callback)
}
}
JPushPlugin.prototype.init = function(){
if(device.platform == "Android") {
data=[];
this.call_native("init",data,null);
}
}
2014-07-22 20:14:01 +08:00
JPushPlugin.prototype.setDebugMode = function(mode){
2014-06-12 14:39:46 +08:00
if(device.platform == "Android") {
2014-07-22 20:14:01 +08:00
this.call_native("setDebugMode",[mode],null);
2014-06-12 14:39:46 +08:00
}
}
2014-07-22 20:14:01 +08:00
//iOS single
2014-06-10 14:14:02 +08:00
if(!window.plugins){
window.plugins = {};
2013-10-18 11:14:33 +08:00
}
2014-06-10 14:14:02 +08:00
2013-10-18 11:14:33 +08:00
if(!window.plugins.jPushPlugin){
2014-06-10 14:14:02 +08:00
window.plugins.jPushPlugin = new JPushPlugin();
}
module.exports = new JPushPlugin();