#pragma mark - 给单一用户进行推送的设置
- (void)jPushSingalUserSetWithUser:(NSString *)user_id {
NSMutableSet *tags = [NSMutableSet set];
//别名,根据用户的UID去设置别名,那么可以指定的推送给某些用户
NSString *alias ;
if (user_id != nil) {
alias =[NSString stringWithFormat:@"%@",user_id];
}
[self analyseInput:&alias tags:&tags];
[JPUSHService setTags:tags alias:alias callbackSelector:@selector(tagsAliasCallback:tags:alias:) object:self];
}
- (void)tagsAliasCallback:(int)iResCode
tags:(NSSet *)tags
alias:(NSString *)alias {
NSString *callbackString =
[NSString stringWithFormat:@"%d, \ntags: %@, \nalias: %@\n", iResCode,
[self logSet:tags], alias];
NSLog(@"TagsAlias回调:%@", callbackString);
}
- (NSString *)logSet:(NSSet *)dic {
if (![dic count]) {
return nil;
}
NSString *tempStr1 =
[[dic description] stringByReplacingOccurrencesOfString:@"\\u"
withString:@"\\U"];
NSString *tempStr2 =
[tempStr1 stringByReplacingOccurrencesOfString:@"\"" withString:@"\\\""];
NSString *tempStr3 =
[[@"\"" stringByAppendingString:tempStr2] stringByAppendingString:@"\""];
NSData *tempData = [tempStr3 dataUsingEncoding:NSUTF8StringEncoding];
NSString *str =
[NSPropertyListSerialization propertyListFromData:tempData
mutabilityOption:NSPropertyListImmutable
format:NULL
errorDescription:NULL];
return str;
}
- (void)analyseInput:(NSString **)alias tags:(NSSet **)tags {
// alias analyse
if (![*alias length]) {
// ignore alias
*alias = nil;
}
// tags analyse
if (![*tags count]) {
*tags = nil;
} else {
__block int emptyStringCount = 0;
[*tags enumerateObjectsUsingBlock:^(NSString *tag, BOOL *stop) {
if ([tag isEqualToString:@""]) {
emptyStringCount++;
} else {
emptyStringCount = 0;
*stop = YES;
}
}];
if (emptyStringCount == [*tags count]) {
*tags = nil;
}
}
}