Update tag & alias methods

This commit is contained in:
Hevin 2017-09-21 19:20:53 +08:00
parent 5c00243986
commit 291aa7b8bf
3 changed files with 142 additions and 22 deletions

View File

@ -92,7 +92,7 @@ public class JPushEventReceiver extends JPushMessageReceiver {
if (jPushMessage.getErrorCode() == 0) { if (jPushMessage.getErrorCode() == 0) {
try { try {
resultJson.put("tag", jPushMessage.getCheckTag()); resultJson.put("tag", jPushMessage.getCheckTag());
resultJson.put("checkResult", jPushMessage.getTagCheckStateResult()); resultJson.put("isBind", jPushMessage.getTagCheckStateResult());
} catch (JSONException e) { } catch (JSONException e) {
e.printStackTrace(); e.printStackTrace();
} }

View File

@ -18,8 +18,17 @@
//以下为js中可调用接口 //以下为js中可调用接口
//设置标签、别名 //设置标签、别名
-(void)setTagsWithAlias:(CDVInvokedUrlCommand*)command; -(void)setTagsWithAlias:(CDVInvokedUrlCommand*)command;
-(void)setTags:(CDVInvokedUrlCommand*)command; -(void)setTags:(CDVInvokedUrlCommand*)command;
-(void)addTags:(CDVInvokedUrlCommand*)command;
-(void)deleteTags:(CDVInvokedUrlCommand*)command;
-(void)cleanTags:(CDVInvokedUrlCommand*)command;
-(void)getAllTags:(CDVInvokedUrlCommand*)command;
-(void)checkTagBindState:(CDVInvokedUrlCommand*)command;
-(void)setAlias:(CDVInvokedUrlCommand*)command; -(void)setAlias:(CDVInvokedUrlCommand*)command;
-(void)deleteAlias:(CDVInvokedUrlCommand*)command;
-(void)getAlias:(CDVInvokedUrlCommand*)command;
//获取 RegistrationID //获取 RegistrationID
-(void)getRegistrationID:(CDVInvokedUrlCommand*)command; -(void)getRegistrationID:(CDVInvokedUrlCommand*)command;

View File

@ -113,34 +113,145 @@
}]; }];
} }
-(void)setTags:(CDVInvokedUrlCommand*)command{ -(void)setTags:(CDVInvokedUrlCommand*)command {
NSArray *tags = command.arguments; NSDictionary* params = [command.arguments objectAtIndex:0];
NSNumber* sequence = params[@"sequence"];
NSArray* tags = params[@"tags"];
[JPUSHService setTags:[NSSet setWithArray:tags] [JPUSHService setTags:[NSSet setWithArray:tags]
alias:nil completion:^(NSInteger iResCode, NSSet *iTags, NSInteger seq) {
fetchCompletionHandle:^(int iResCode, NSSet *iTags, NSString *iAlias) { NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
CDVPluginResult *result; [dic setObject:sequence forKey:@"sequence"];
if (iResCode == 0) {
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:nil]; CDVPluginResult* result;
if (iResCode == 0) { // success
[dic setObject:[iTags allObjects] forKey:@"tags"];
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:dic];
} else { } else {
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:nil]; [dic setValue:[NSNumber numberWithUnsignedInteger:iResCode] forKey:@"errorCode"];
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:dic];
} }
[self.commandDelegate sendPluginResult:result callbackId:command.callbackId]; [self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
}]; } seq:[sequence integerValue]];
} }
-(void)setAlias:(CDVInvokedUrlCommand*)command{ -(void)addTags:(CDVInvokedUrlCommand *)command {
NSString *alias = [command argumentAtIndex:0]; NSDictionary* params = [command.arguments objectAtIndex:0];
[JPUSHService setTags:nil NSNumber* sequence = params[@"sequence"];
alias:alias NSArray* tags = params[@"tags"];
fetchCompletionHandle:^(int iResCode, NSSet *iTags, NSString *iAlias) {
CDVPluginResult *result; [JPUSHService addTags:[NSSet setWithArray:tags]
if (iResCode == 0) { completion:^(NSInteger iResCode, NSSet *iTags, NSInteger seq) {
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:nil]; NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
[dic setObject:sequence forKey:@"sequence"];
CDVPluginResult* result;
if (iResCode == 0) { // success
[dic setObject:[iTags allObjects] forKey:@"tags"];
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:dic];
} else { } else {
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:nil]; [dic setValue:[NSNumber numberWithUnsignedInteger:iResCode] forKey:@"errorCode"];
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:dic];
} }
[self.commandDelegate sendPluginResult:result callbackId:command.callbackId]; [self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
}]; } seq:[sequence integerValue]];
}
-(void)deleteTags:(CDVInvokedUrlCommand *)command {
NSDictionary* params = [command.arguments objectAtIndex:0];
NSNumber* sequence = params[@"sequence"];
NSArray* tags = params[@"tags"];
[JPUSHService deleteTags:[NSSet setWithArray:tags]
completion:^(NSInteger iResCode, NSSet *iTags, NSInteger seq) {
NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
[dic setObject:sequence forKey:@"sequence"];
CDVPluginResult* result;
if (iResCode == 0) { // success
[dic setObject:[iTags allObjects] forKey:@"tags"];
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:dic];
} else {
[dic setValue:[NSNumber numberWithUnsignedInteger:iResCode] forKey:@"errorCode"];
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:dic];
}
[self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
} seq:[sequence integerValue]];
}
-(void)cleanTags:(CDVInvokedUrlCommand *)command {
NSDictionary* params = [command.arguments objectAtIndex:0];
NSNumber* sequence = params[@"sequence"];
[JPUSHService cleanTags:^(NSInteger iResCode, NSSet *iTags, NSInteger seq) {
NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
[dic setObject:sequence forKey:@"sequence"];
CDVPluginResult* result;
if (iResCode == 0) {
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:dic];
} else {
[dic setValue:[NSNumber numberWithUnsignedInteger:iResCode] forKey:@"errorCode"];
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:dic];
}
[self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
} seq:[sequence integerValue]];
}
-(void)getAllTags:(CDVInvokedUrlCommand *)command {
NSDictionary* params = [command.arguments objectAtIndex:0];
NSNumber* sequence = params[@"sequence"];
[JPUSHService getAllTags:^(NSInteger iResCode, NSSet *iTags, NSInteger seq) {
NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
[dic setObject:sequence forKey:@"sequence"];
CDVPluginResult* result;
if (iResCode == 0) { // success
[dic setObject:[iTags allObjects] forKey:@"tags"];
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:dic];
} else {
[dic setValue:[NSNumber numberWithUnsignedInteger:iResCode] forKey:@"errorCode"];
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:dic];
}
[self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
} seq:[sequence integerValue]];
}
-(void)checkTagBindState:(CDVInvokedUrlCommand *)command {
NSDictionary* params = [command.arguments objectAtIndex:0];
NSNumber* sequence = params[@"sequence"];
NSString* tag = params[@"tag"];
[JPUSHService validTag:tag completion:^(NSInteger iResCode, NSSet *iTags, NSInteger seq, BOOL isBind) {
NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
[dic setObject:sequence forKey:@"sequence"];
CDVPluginResult* result;
if (iResCode == 0) { // success
[dic setObject:[iTags allObjects] forKey:@"tags"];
[dic setObject:[NSNumber numberWithBool:isBind] forKey:@"isBind"];
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:dic];
} else {
[dic setValue:[NSNumber numberWithUnsignedInteger:iResCode] forKey:@"errorCode"];
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:dic];
}
} seq:[sequence integerValue]];
}
-(void)setAlias:(CDVInvokedUrlCommand*)command {
} }
-(void)getRegistrationID:(CDVInvokedUrlCommand*)command{ -(void)getRegistrationID:(CDVInvokedUrlCommand*)command{