普通情况下,推送要区分不同环境,则分多个证书。但如果想只用一个证书来让后台区分所有的环境,要怎么实现呢?以下极光推送为例,在设置极光推送别名的时候加以区分
1、iOS 端,以debug/uat/release前缀区分环境,拼接用户 ID 等信息进行精准推送,代码示例如下 :
- (void)setAlias {
NSInteger userID = [LHDefaults integerForKey:kUserId];
//当测试环境或UAT环境时,添加debug|来屏蔽测试环境的数据发到生产环境。
LHEnvironmentType type = [LHEnvironment sharedInstance].currentEnvironment;
NSString *alias = @"";
if (type == LHEnvironmentTypeDEV || type == LHEnvironmentTypeTEST) {
alias = [NSString stringWithFormat:@"debug|%zd", userID];
} else if (type == LHEnvironmentTypeUAT) {
alias = [NSString stringWithFormat:@"uat|%zd", userID];
} else {
//Production
alias = [NSString stringWithFormat:@"%zd", userID];
}
[JPUSHService setAlias:alias completion:^(NSInteger iResCode, NSString *iAlias, NSInteger seq) {
NSLog(@"jasdnfjas");
} seq:1];
}
2、极光测试数据