delete notifacation center

This commit is contained in:
zhangqinhghe 2014-06-10 14:14:02 +08:00
parent f2918e7d9c
commit 60eefc2b5b
4 changed files with 161 additions and 284 deletions

View File

@ -5,61 +5,21 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Phonegap Sample App</title>
<link href="css/jquery.mobile-1.1.1.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/jquery.mobile-1.1.1.js"></script>
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript">
var onDeviceReady = function() {
console.log("Device ready!")
initiateUI();
<script type="text/javascript">
var onDeviceReady = function(){
console.log("Device ready!")
initiateUI();
}
var onTagsWithAlias = function(data) {
var onTagsWithAlias = function(event){
try{
var tagaliasJson=window.plugins.jPushPlugin.parseEvent(data);
$("#tagAliasResult").html(tagaliasJson);;
}
catch(exception){
console.log(exception)
}
}
var onDidSetup = function() {
try{
$("#connectState").html("建立连接");;
}
catch(exception){
console.log(exception)
}
}
var onDidClose = function() {
try{
$("#connectState").html("连接关闭");;
}
catch(exception){
console.log(exception)
}
}
var onDidRegister = function() {
try{
$("#connectState").html("注册成功");;
}
catch(exception){
console.log(exception)
}
}
var onDidLogin = function() {
try{
$("#connectState").html("登录成功");;
var result="result code:"+event.resultCode+" ";
result+="tags:"+event.tags;
result+="alias"+event.alias;
$("#tagAliasResult").html(result);
}
catch(exception){
console.log(exception)
@ -67,64 +27,45 @@
}
var onGetRegistradionID = function(data) {
try{
var registrationID=window.plugins.jPushPlugin.parseEvent(data);
$("#registrationid").html(registrationID);;
$("#registrationid").html(data);
}
catch(exception){
console.log(exception)
console.log(exception);
}
}
var initiateUI = function() {
window.plugins.jPushPlugin.getRegistrationID();
window.plugins.jPushPlugin.initNotificationCenter();
var initiateUI = function(){
window.plugins.jPushPlugin.getRegistrationID(onGetRegistradionID);
window.plugins.jPushPlugin.startLogPageView("mianPage");
//window.plugins.jPushPlugin.stopLogPageView("mianPage");
$("#setTagWithAliasButton").click(function(ev) {
try{
var tag1 = $("#tagText1").attr("value");
var tag2 = $("#tagText2").attr("value");
var tag3 = $("#tagText3").attr("value");
try{
var tag1 = $("#tagText1").attr("value");
var tag2 = $("#tagText2").attr("value");
var tag3 = $("#tagText3").attr("value");
var alias = $("#aliasText").attr("value");
var dd = [];
var alias = $("#aliasText").attr("value");
var dd = [];
if(tag1==""&&tag2==""&&tag3==""){
}
else{
if(tag1 != "")
dd.push(tag1);
if(tag2 != "")
dd.push(tag2);
if(tag3 != "")
dd.push(tag3);
}
console.log("dd:"+dd);
window.plugins.jPushPlugin.setTagsWithAlias(dd,"");
}
catch(exception){
console.log(exception);
if(tag1==""&&tag2==""&&tag3==""){
}
else{
if(tag1 != ""){
dd.push(tag1);
}
if(tag2 != ""){
dd.push(tag2);
}
if(tag3 != ""){
dd.push(tag3);
}
}
window.plugins.jPushPlugin.setTagsWithAlias(dd,"");
}
catch(exception){
console.log(exception);
}
})
}
document.addEventListener("networkDidSetup", onDidSetup, false)
document.addEventListener("networkDidClose", onDidClose, false)
document.addEventListener("networkDidRegister", onDidRegister, false)
document.addEventListener("networkDidLogin", onDidLogin, false)
document.addEventListener("setTagsWithAlias", onTagsWithAlias, false)
document.addEventListener("registrationID", onGetRegistradionID, false)
document.addEventListener("deviceready", onDeviceReady, false)
document.addEventListener("jpush.setTagsWithAlias", onTagsWithAlias, false);
document.addEventListener("deviceready", onDeviceReady, false);
</script>
</head>
<body>
@ -145,10 +86,6 @@
<label>RegistrationID: </label>
<label id="registrationid">null</label>
</div>
<div>
<label>connected state: </label>
<label id="connectState">未连接</label>
</div>
<div data-role="fieldcontain">
<label>Tags: </label>
<table>
@ -183,7 +120,6 @@
<div data-role="fieldcontain">
<label id="tagAliasResult" >null</label>
</div>
</div>
</form>
</div>

View File

@ -16,7 +16,6 @@
-(void)setTags:(CDVInvokedUrlCommand*)command;
-(void)setAlias:(CDVInvokedUrlCommand*)command;
-(void)getRegistrationID:(CDVInvokedUrlCommand*)command;
-(void)initNotifacationCenter:(CDVInvokedUrlCommand*)command;
-(void)startLogPageView:(CDVInvokedUrlCommand*)command;
-(void)stopLogPageView:(CDVInvokedUrlCommand*)command;

View File

@ -11,7 +11,6 @@
@implementation JPushPlugin
-(void)setTagsWithAlias:(CDVInvokedUrlCommand*)command{
NSArray *arguments=command.arguments;
@ -21,18 +20,15 @@
}
NSString *alias=[arguments objectAtIndex:0];
NSArray *arrayTags=[arguments objectAtIndex:1];
// NSArray *tags=[arguments subarrayWithRange:range];
NSSet* set=[NSSet setWithArray:arrayTags];
[APService setTags:set
alias:alias
callbackSelector:@selector(tagsWithAliasCallback:tags:alias:)
object:self];
//[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}
-(void)setTags:(CDVInvokedUrlCommand *)command{
//CDVPluginResult *pluginResult=nil;
NSArray *arguments=[command arguments];
NSString *tags=[arguments objectAtIndex:0];
@ -41,89 +37,52 @@
[APService setTags:[NSSet setWithArray:array]
callbackSelector:@selector(tagsWithAliasCallback:tags:alias:)
object:self];
//[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}
-(void)setAlias:(CDVInvokedUrlCommand *)command{
CDVPluginResult *pluginResult=nil;
NSArray *arguments=[command arguments];
[APService setAlias:[arguments objectAtIndex:0]
callbackSelector:@selector(tagsWithAliasCallback:tags:alias:)
object:self];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}
-(void)getRegistrationID:(CDVInvokedUrlCommand*)command{
NSString* registratonID = [APService registrionID];
dispatch_async(dispatch_get_main_queue(), ^{
//
NSString *script=[NSString stringWithFormat:@"cordova.fireDocumentEvent('registrationID','[%@]')",registratonID];
[self.commandDelegate evalJs:script];
[self writeJavascript:[NSString stringWithFormat:@"window.plugins.jPushPlugin.registrationCallback('%@')",registratonID]];
});
CDVPluginResult *result=[self pluginResultForValue:registratonID];
if (result) {
[self succeedWithPluginResult:result withCallbackID:command.callbackId];
} else {
[self failWithCallbackID:command.callbackId];
}
}
-(void)tagsWithAliasCallback:(int)resultCode tags:(NSSet *)tags alias:(NSString *)alias{
NSLog(@"recode is %d tags is %@ alias %@",resultCode,tags,alias);
NSDictionary *dict=[NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt:resultCode],@"resultCode",
tags==nil?[NSNull null]:[tags allObjects],@"resultTags",
alias==nil?[NSNull null]:alias,@"resultAlias",nil];
tags==nil?[NSNull null]:[tags allObjects],@"tags",
alias==nil?[NSNull null]:alias,@"alias",nil];
NSMutableDictionary *data = [NSMutableDictionary dictionary];
[data setObject:[NSNumber numberWithInt:resultCode] forKey:@"resultCode"];
[data setObject:tags==nil?[NSNull null]:[tags allObjects] forKey:@"tags"];
[data setObject:alias==nil?[NSNull null]:alias forKey:@"alias"];
NSError *error;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dict options:0 error:&error];
NSString *jsonString = [[NSString alloc]initWithData:jsonData encoding:NSUTF8StringEncoding];
dispatch_async(dispatch_get_main_queue(), ^{
[self.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.fireDocumentEvent('setTagsWithAlias','[%@]')",jsonString]];
[self writeJavascript:[NSString stringWithFormat:@"window.plugins.jPushPlugin.pushCallback('%@')",jsonString]];
[self.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.fireDocumentEvent('jpush.setTagsWithAlias',%@)",jsonString]];
[self writeJavascript:[NSString stringWithFormat:@"window.plugins.jPushPlugin.pushCallback('%@')",jsonString]];
});
}
- (void)networkDidSetup:(NSNotification *)notification {
[self.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.fireDocumentEvent('networkDidSetup')"]];
}
- (void)networkDidClose:(NSNotification *)notification {
[self.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.fireDocumentEvent('networkDidClose')"]];
}
- (void)networkDidRegister:(NSNotification *)notification {
[self.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.fireDocumentEvent('networkDidRegister')"]];
}
- (void)networkDidLogin:(NSNotification *)notification {
[self.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.fireDocumentEvent('networkDidLogin')"]];
}
-(void)initNotifacationCenter:(CDVInvokedUrlCommand*)command{
NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter];
[defaultCenter addObserver:self
selector:@selector(networkDidSetup:)
name:kAPNetworkDidSetupNotification
object:nil];
[defaultCenter addObserver:self
selector:@selector(networkDidClose:)
name:kAPNetworkDidCloseNotification
object:nil];
[defaultCenter addObserver:self
selector:@selector(networkDidRegister:)
name:kAPNetworkDidRegisterNotification
object:nil];
[defaultCenter addObserver:self
selector:@selector(networkDidLogin:)
name:kAPNetworkDidLoginNotification
object:nil];
}
-(void)startLogPageView:(CDVInvokedUrlCommand*)command{
NSArray *arguments=command.arguments;
if (!arguments||[arguments count]<1) {
@ -148,5 +107,39 @@
}
- (void)failWithCallbackID:(NSString *)callbackID {
CDVPluginResult *result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
[self.commandDelegate sendPluginResult:result callbackId:callbackID];
}
- (void)succeedWithPluginResult:(CDVPluginResult *)result withCallbackID:(NSString *)callbackID {
[self.commandDelegate sendPluginResult:result callbackId:callbackID];
}
- (CDVPluginResult *)pluginResultForValue:(id)value {
CDVPluginResult *result;
if ([value isKindOfClass:[NSString class]]) {
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK
messageAsString:[value stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
} else if ([value isKindOfClass:[NSNumber class]]) {
CFNumberType numberType = CFNumberGetType((CFNumberRef)value);
//note: underlyingly, BOOL values are typedefed as char
if (numberType == kCFNumberIntType || numberType == kCFNumberCharType) {
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsInt:[value intValue]];
} else {
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDouble:[value doubleValue]];
}
} else if ([value isKindOfClass:[NSArray class]]) {
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsArray:value];
} else if ([value isKindOfClass:[NSDictionary class]]) {
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:value];
} else if ([value isKindOfClass:[NSNull class]]) {
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
} else {
NSLog(@"Cordova callback block returned unrecognized type: %@", NSStringFromClass([value class]));
return nil;
}
return result;
}
@end

View File

@ -1,139 +1,88 @@
cordova.define("cn.jpush.phonegap.JPushPlugin.JPushPlugin", function(require, exports, module) {
var JPushPlugin = function(){
};
JPushPlugin.prototype.call_native = function ( name, args) {
ret = cordova.exec(null,
null,
'JPushPlugin',
name,
args);
return ret;
}
JPushPlugin.prototype.getRegistrationID = function () {
this.call_native( "getRegistrationID", null);
JPushPlugin.prototype.error_callback = function(msg){
console.log("Javascript Callback Error: " + msg)
}
JPushPlugin.prototype.startLogPageView = function (data) {
if (data==null || typeof(data)=="undefined" || data==""){
console.log("argument is null");
JPushPlugin.prototype.call_native = function(name, args, callback){
ret = cordova.exec(callback,this.error_callback,'JPushPlugin',name,args);
return ret;
}
JPushPlugin.prototype.getRegistrationID = function(callback){
this.call_native("getRegistrationID",null,callback);
}
JPushPlugin.prototype.startLogPageView = function(data){
this.call_native( "startLogPageView",[data],null);
}
JPushPlugin.prototype.stopLogPageView = function(data){
this.call_native( "stopLogPageView",[data],null);
}
JPushPlugin.prototype.setTagsWithAlias = function(tags,alias){
if(tags==null){
this.setAlias(alias);
return;
}
else{
this.call_native( "startLogPageView", [data]);
}
}
JPushPlugin.prototype.stopLogPageView = function (data) {
if (data==null || typeof(data)=="undefined" || data==""){
console.log("argument is null");
}
else{
this.call_native( "stopLogPageView", [data]);
}
}
JPushPlugin.prototype.initNotificationCenter = function () {
this.call_native( "initNotifacationCenter", null);
}
JPushPlugin.prototype.parseEvent = function (data) {
try{
var parament=""
var count=1;
var start=false;
for(var i in data){
if(data[i]=='['){
if (count==1&&start==false) {
start=true;
continue;
}
count++;
}
if (data[i]==']') {
if(count==1)
{
break;
}
count--;
}
parament+=data[i]
}
return parament;
}
catch(exception){
alert(exception);
}
if(alias==null){
this.setTags(tags);
return;
}
var arrayTagWithAlias=[tags];
arrayTagWithAlias.unshift(alias);
this.call_native( "setTagsWithAlias", arrayTagWithAlias,null);
}
JPushPlugin.prototype.setTagsWithAlias = function (tags,alias) {
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);
}
JPushPlugin.prototype.setTags = function (data) {
JPushPlugin.prototype.setTags = function(data){
try{
this.call_native("setTags", [data]);
}
catch(exception){
console.log(exception);
}
try{
this.call_native("setTags",[data],null);
}
catch(exception){
console.log(exception);
}
}
JPushPlugin.prototype.setAlias = function (data) {
try{
this.call_native("setAlias", [data]);
}
catch(exception){
console.log(exception);
}
JPushPlugin.prototype.setAlias = function(data){
try{
this.call_native("setAlias", [data],null);
}
catch(exception){
console.log(exception);
}
}
JPushPlugin.prototype.pushCallback = function (data) {
try{
var bToObj=JSON.parse(data);
var code = bToObj.resultCode;
var tags = bToObj.resultTags;
var alias = bToObj.resultAlias;
console.log("JPushPlugin:callBack--code is "+code+" tags is "+tags + " alias is "+alias);
}
catch(exception){
console.log(exception);
}
JPushPlugin.prototype.pushCallback = function(data){
try{
var bToObj=JSON.parse(data);
var code = bToObj.resultCode;
var tags = bToObj.resultTags;
var alias = bToObj.resultAlias;
console.log("JPushPlugin:callBack--code is "+code+" tags is "+tags + " alias is "+alias);
}
catch(exception){
console.log(exception);
}
}
JPushPlugin.prototype.registrationCallback = function (data) {
try{
console.log("registrationCallback--registraionID is "+data);
}
catch(exception){
console.log(exception);
}
//android
//ios
JPushPlugin.prototype.initNotificationCenter = function(){
this.call_native( "initNotifacationCenter", null,null);
}
if(!window.plugins) {
window.plugins = {};
if(!window.plugins){
window.plugins = {};
}
if(!window.plugins.jPushPlugin){
window.plugins.jPushPlugin = new JPushPlugin();
}
module.exports = new JPushPlugin();
window.plugins.jPushPlugin = new JPushPlugin();
}
module.exports = new JPushPlugin();
});