From 291aa7b8bfe63b14dbc367c40d733eb20715a686 Mon Sep 17 00:00:00 2001 From: Hevin Date: Thu, 21 Sep 2017 19:20:53 +0800 Subject: [PATCH] Update tag & alias methods --- src/android/JPushEventReceiver.java | 2 +- src/ios/Plugins/JPushPlugin.h | 9 ++ src/ios/Plugins/JPushPlugin.m | 153 ++++++++++++++++++++++++---- 3 files changed, 142 insertions(+), 22 deletions(-) diff --git a/src/android/JPushEventReceiver.java b/src/android/JPushEventReceiver.java index 3d96251..da6f1b8 100644 --- a/src/android/JPushEventReceiver.java +++ b/src/android/JPushEventReceiver.java @@ -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(); } diff --git a/src/ios/Plugins/JPushPlugin.h b/src/ios/Plugins/JPushPlugin.h index daf08b2..7c7da19 100644 --- a/src/ios/Plugins/JPushPlugin.h +++ b/src/ios/Plugins/JPushPlugin.h @@ -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; diff --git a/src/ios/Plugins/JPushPlugin.m b/src/ios/Plugins/JPushPlugin.m index 6ca27e2..2c4e454 100644 --- a/src/ios/Plugins/JPushPlugin.m +++ b/src/ios/Plugins/JPushPlugin.m @@ -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{