CNUserAgreementManager.m
10.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
//
// CNUserAgreementManager.m
// Test
//
// Created by CNLive-zxw on 2019/4/13.
// Copyright © 2019 CNLive. All rights reserved.
//
#import "CNUserAgreementManager.h"
#import "CNUserAgreementWebController.h"
#import "CNLiveNetworking.h"
#import "CNLiveEnvironment.h"
@BeeHiveService(CNLiveUserAgreementServiceProtocol,CNUserAgreementManager)
@interface CNUserAgreementManager ()<CNLiveUserAgreementServiceProtocol>
@end
@implementation CNUserAgreementManager
static CNUserAgreementManager *_instance = nil;
/**
* @abstract 单例初始化
*/
+ (instancetype)manager{
static dispatch_once_t once;
dispatch_once(&once, ^{
_instance = [[CNUserAgreementManager alloc]init];
});
return _instance;
}
+ (id)allocWithZone:(struct _NSZone *)zone{
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
_instance = [super allocWithZone:zone];
});
return _instance;
}
- (nonnull id)copyWithZone:(nullable NSZone *)zone {
return _instance;
}
- (nonnull id)mutableCopyWithZone:(nullable NSZone *)zone {
return _instance;
}
+ (void)jumpToAgreementH5WithType:(CNGetAgreementH5Type)type {
[CNUserAgreementManager getAgreementH5WithType:type success:^(NSString *h5, NSString *title) {
UIViewController *root = [UIApplication sharedApplication].delegate.window.rootViewController;
//跟控制器是Navigation
if ([root isKindOfClass:[UINavigationController class]]){
UINavigationController *nav = (UINavigationController *)root;
CNUserAgreementWebController *vc = [[CNUserAgreementWebController alloc] initWithUrl:h5 name:title];
[nav pushViewController:vc animated:YES];
}
//跟控制器是TabBar
else if ([root isKindOfClass:[UITabBarController class]]){
UITabBarController *tab = (UITabBarController *)root;
UINavigationController *nav = tab.selectedViewController;
CNUserAgreementWebController *vc = [[CNUserAgreementWebController alloc] initWithUrl:h5 name:title];
[nav pushViewController:vc animated:YES];
}else{
CNUserAgreementWebController *vc = [[CNUserAgreementWebController alloc] initWithUrl:h5 name:title];
[root presentViewController:vc animated:YES completion:nil];
}
} failure:^(NSError *error) {
}];
}
+ (void)getAgreementH5WithType:(CNGetAgreementH5Type)type success:(SuccessBlock)success failure:(FailureBlock)failure {
[[CNUserAgreementManager manager] getAgreementH5WithType:type success:^(NSString * _Nonnull h5, NSString * _Nonnull title) {
success(h5, title);
} failure:^(NSError * _Nonnull error) {
failure(error);
}];
}
- (void)getAgreementH5WithType:(CNGetAgreementH5Type)type success:(SuccessBlock)success failure:(FailureBlock)failure {
[CNLiveNetworking setAllowRequestDefaultArgument:NO];
[CNLiveNetworking requestNetworkWithMethod:CNLiveRequestMethodGET URLString:CNGetAgreementH5Url Param:@{} CacheType:CNLiveNetworkCacheTypeNetworkOnly CompletionBlock:^(NSURLSessionTask *requestTask, id responseObject, NSError *error) {
if (error) {
if (failure) {
failure(error);
}
}
else{
if ([responseObject isKindOfClass:[NSArray class]]) {
for (NSDictionary *dic in responseObject) {
switch (type) {
case CNAgreementUser:
{
if ([[NSString stringWithFormat:@"%@",dic[@"type"]] isEqualToString:@"yhxy"]) {
if (success) {
success(dic[@"detailUrl"],dic[@"title"]);
return ;
}
}
}
break;
case CNAgreementPrivacy:
{
if ([[NSString stringWithFormat:@"%@",dic[@"type"]] isEqualToString:@"yszc"]) {
if (success) {
success(dic[@"detailUrl"],dic[@"title"]);
return ;
}
}
}
break;
case CNAgreementHelp:
{
if ([[NSString stringWithFormat:@"%@",dic[@"type"]] isEqualToString:@"bzfk"]) {
if (success) {
success(dic[@"detailUrl"],dic[@"title"]);
return ;
}
}
}
break;
case CNAgreementUnderstand:
{
if ([[NSString stringWithFormat:@"%@",dic[@"type"]] isEqualToString:@"ljwjj"]) {
if (success) {
success(dic[@"detailUrl"],dic[@"title"]);
return ;
}
}
}
break;
case CNAgreementIntroduction:
{
if ([[NSString stringWithFormat:@"%@",dic[@"type"]] isEqualToString:@"yyjj"]) {
if (success) {
success(dic[@"detailUrl"],dic[@"title"]);
return ;
}
}
}
break;
case CNAgreementCopyright:
{
if ([[NSString stringWithFormat:@"%@",dic[@"type"]] isEqualToString:@"bqxx"]) {
if (success) {
success(dic[@"detailUrl"],dic[@"title"]);
return ;
}
}
}
break;
case CNAgreementPermission:
{
if ([[NSString stringWithFormat:@"%@",dic[@"type"]] isEqualToString:@"rjxkxy"]) {
if (success) {
success(dic[@"detailUrl"],dic[@"title"]);
return ;
}
}
}
break;
case CNAgreementIntegralRules:
{
if ([[NSString stringWithFormat:@"%@",dic[@"type"]] isEqualToString:@"jfgz"]) {
if (success) {
success(dic[@"detailUrl"],dic[@"title"]);
return ;
}
}
}
break;
case CNAgreementSigninRules:
{
if ([[NSString stringWithFormat:@"%@",dic[@"type"]] isEqualToString:@"jfjlgz"]) {
if (success) {
success(dic[@"detailUrl"],dic[@"title"]);
return ;
}
}
}
break;
case CNAgreementReviewApply:
{
if ([[NSString stringWithFormat:@"%@",dic[@"type"]] isEqualToString:@"shsqxy"]) {
if (success) {
success(dic[@"detailUrl"],dic[@"title"]);
return ;
}
}
}
break;
case CNAgreementCancellation:
{
if ([[NSString stringWithFormat:@"%@",dic[@"type"]] isEqualToString:@"zxxz"]) {
if (success) {
success(dic[@"detailUrl"],dic[@"title"]);
return ;
}
}
}
break;
case CNAgreementEmojiService:
{
if ([[NSString stringWithFormat:@"%@",dic[@"type"]] isEqualToString:@"fwsm"]) {
if (success) {
success(dic[@"detailUrl"],dic[@"title"]);
return ;
}
}
}
break;
case CNAgreementEmojiComplaints:
{
if ([[NSString stringWithFormat:@"%@",dic[@"type"]] isEqualToString:@"tssm"]) {
if (success) {
success(dic[@"detailUrl"],dic[@"title"]);
return ;
}
}
}
break;
case CNAgreementEnterpriseQualification:
{
if ([[NSString stringWithFormat:@"%@",dic[@"type"]] isEqualToString:@"qyzz"]) {
if (success) {
success(dic[@"detailUrl"],dic[@"title"]);
return ;
}
}
}
break;
default:
break;
}
}
}
if (failure) {
failure(error);
}
}
}];
}
@end