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) {
try {
resultJson.put("tag", jPushMessage.getCheckTag());
resultJson.put("checkResult", jPushMessage.getTagCheckStateResult());
resultJson.put("isBind", jPushMessage.getTagCheckStateResult());
} catch (JSONException e) {
e.printStackTrace();
}

View File

@ -18,8 +18,17 @@
//以下为js中可调用接口
//设置标签、别名
-(void)setTagsWithAlias:(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)deleteAlias:(CDVInvokedUrlCommand*)command;
-(void)getAlias:(CDVInvokedUrlCommand*)command;
//获取 RegistrationID
-(void)getRegistrationID:(CDVInvokedUrlCommand*)command;

View File

@ -113,34 +113,145 @@
}];
}
-(void)setTags:(CDVInvokedUrlCommand*)command{
NSArray *tags = command.arguments;
-(void)setTags:(CDVInvokedUrlCommand*)command {
NSDictionary* params = [command.arguments objectAtIndex:0];
NSNumber* sequence = params[@"sequence"];
NSArray* tags = params[@"tags"];
[JPUSHService setTags:[NSSet setWithArray:tags]
alias:nil
fetchCompletionHandle:^(int iResCode, NSSet *iTags, NSString *iAlias) {
CDVPluginResult *result;
if (iResCode == 0) {
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:nil];
} else {
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:nil];
}
[self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
}];
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)setAlias:(CDVInvokedUrlCommand*)command{
NSString *alias = [command argumentAtIndex:0];
[JPUSHService setTags:nil
alias:alias
fetchCompletionHandle:^(int iResCode, NSSet *iTags, NSString *iAlias) {
CDVPluginResult *result;
-(void)addTags:(CDVInvokedUrlCommand *)command {
NSDictionary* params = [command.arguments objectAtIndex:0];
NSNumber* sequence = params[@"sequence"];
NSArray* tags = params[@"tags"];
[JPUSHService addTags:[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)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 messageAsString:nil];
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:dic];
} 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];
}];
} 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{