Commit ed9502424c2faa7e98d1ba35161d2fbe9336ad69

Authored by zhangxiaowen
1 parent 1400df32

no message

CNLiveUserAgreementManager/Assets/CNLiveAgreementManager.bundle/web_black_back@2x.png

628 Bytes | W: | H:

1.49 KB | W: | H:

  • 2-up
  • Swipe
  • Onion skin
CNLiveUserAgreementManager/Assets/CNLiveAgreementManager.bundle/web_black_back@3x.png

1.15 KB | W: | H:

1.79 KB | W: | H:

  • 2-up
  • Swipe
  • Onion skin
CNLiveUserAgreementManager/Assets/CNLiveAgreementManager.bundle/web_black_close@2x.png 0 → 100644

2.92 KB

CNLiveUserAgreementManager/Assets/CNLiveAgreementManager.bundle/web_black_close@3x.png 0 → 100644

4.14 KB

CNLiveUserAgreementManager/Classes/CNLiveAgreementManager.h
... ... @@ -42,6 +42,22 @@ typedef void(^FailureBlock)(NSError *error);
42 42 + (void)jumpToAgreementH5WithString:(NSString *)string;
43 43  
44 44 /**
  45 + * 类方法 请求协议
  46 + * @param string 类型字符串
  47 + * @param success 请求成功回调
  48 + * @param failure 请求失败回调
  49 + */
  50 ++ (void)getAgreementH5WithString:(NSString *)string success:(SuccessBlock)success failure:(FailureBlock)failure;
  51 +
  52 +/**
  53 + * 对象方法 请求协议
  54 + * @param string 类型字符串
  55 + * @param success 请求成功回调
  56 + * @param failure 请求失败回调
  57 + */
  58 +- (void)getAgreementH5WithString:(NSString *)string success:(SuccessBlock)success failure:(FailureBlock)failure;
  59 +
  60 +/**
45 61 * 请求协议并跳转
46 62 * @param type 类型
47 63 */
... ...
CNLiveUserAgreementManager/Classes/CNLiveAgreementManager.m
... ... @@ -48,6 +48,7 @@ static CNLiveAgreementManager *_instance = nil;
48 48 return _instance;
49 49 }
50 50  
  51 +#pragma mark - 类型
51 52 - (void)getAgreementH5WithType:(CNGetAgreementH5Type)type success:(SuccessBlock)success failure:(FailureBlock)failure {
52 53 [CNLiveNetworking setAllowRequestDefaultArgument:NO];
53 54 [CNLiveNetworking requestNetworkWithMethod:CNLiveRequestMethodGET URLString:CNGetAgreementH5Url Param:@{} CacheType:CNLiveNetworkCacheTypeNetworkOnly CompletionBlock:^(NSURLSessionTask *requestTask, id responseObject, NSError *error) {
... ... @@ -229,55 +230,106 @@ static CNLiveAgreementManager *_instance = nil;
229 230  
230 231 + (void)getAgreementH5WithType:(CNGetAgreementH5Type)type success:(SuccessBlock)success failure:(FailureBlock)failure {
231 232 [[CNLiveAgreementManager manager] getAgreementH5WithType:type success:^(NSString * _Nonnull h5, NSString * _Nonnull title) {
232   - success(h5, title);
  233 + success?success(h5, title):@"";
233 234  
234 235 } failure:^(NSError * _Nonnull error) {
235   - failure(error);
  236 + failure?failure(error):@"";
236 237  
237 238 }];
238 239  
239 240 }
240 241  
241 242 + (void)jumpToAgreementH5WithType:(CNGetAgreementH5Type)type{
242   -
  243 + __weak typeof(self) weakSelf = self;
243 244 [CNLiveAgreementManager getAgreementH5WithType:type success:^(NSString *h5, NSString *title) {
244   -
245   - [self pushToWebControllerUrl:h5 name:title];
  245 + __strong typeof(weakSelf) strongSelf = weakSelf;
  246 + if(!strongSelf) return;
  247 + [strongSelf pushToWebControllerUrl:h5 name:title showCloseBtn:YES];
246 248  
247 249 } failure:^(NSError *error) {
248   -
  250 + if(TestEnvironment){
  251 + NSLog(@"点击协议跳转失败");
  252 +
  253 + }
249 254 }];
250 255  
251 256 }
252 257  
  258 +#pragma mark - 类型字符串
  259 +/**
  260 + * 请求协议并跳转
  261 + * @param string 类型字符串
  262 + */
253 263 + (void)jumpToAgreementH5WithString:(NSString *)string {
  264 + __weak typeof(self) weakSelf = self;
  265 + [CNLiveAgreementManager getAgreementH5WithString:string success:^(NSString *h5, NSString *title) {
  266 + __strong typeof(weakSelf) strongSelf = weakSelf;
  267 + if(!strongSelf) return;
  268 + [strongSelf pushToWebControllerUrl:h5 name:title showCloseBtn:NO];
  269 +
  270 + } failure:^(NSError *error) {
  271 + if(TestEnvironment){
  272 + NSLog(@"点击协议跳转失败");
  273 +
  274 + }
  275 + }];
  276 +
  277 +}
  278 +
  279 +/**
  280 + * 类方法 请求协议
  281 + * @param string 类型字符串
  282 + * @param success 请求成功回调
  283 + * @param failure 请求失败回调
  284 + */
  285 ++ (void)getAgreementH5WithString:(NSString *)string success:(SuccessBlock)success failure:(FailureBlock)failure{
  286 + [[CNLiveAgreementManager manager] getAgreementH5WithString:string success:^(NSString *h5, NSString *title) {
  287 + success?success(h5, title):@"";
  288 +
  289 + } failure:^(NSError *error) {
  290 + failure?failure(error):@"";
  291 +
  292 + }];
  293 +}
  294 +
  295 +/**
  296 + * 对象方法 请求协议
  297 + * @param string 类型字符串
  298 + * @param success 请求成功回调
  299 + * @param failure 请求失败回调
  300 + */
  301 +- (void)getAgreementH5WithString:(NSString *)string success:(SuccessBlock)success failure:(FailureBlock)failure{
254 302 [CNLiveNetworking setAllowRequestDefaultArgument:NO];
255 303 [CNLiveNetworking requestNetworkWithMethod:CNLiveRequestMethodGET URLString:CNGetAgreementH5Url Param:@{} CacheType:CNLiveNetworkCacheTypeNetworkOnly CompletionBlock:^(NSURLSessionTask *requestTask, id responseObject, NSError *error) {
256 304 if (!error) {
257 305 if ([responseObject isKindOfClass:[NSArray class]]) {
258 306 for (NSDictionary *dic in responseObject) {
259 307 if ([[NSString stringWithFormat:@"%@",dic[@"type"]] isEqualToString:string]) {
260   - [self pushToWebControllerUrl:dic[@"detailUrl"] name:dic[@"title"]];
261   - break;
  308 + success?success(dic[@"detailUrl"], dic[@"title"]):@"";
  309 + return;
262 310 }
263 311  
264 312 }
265 313  
266 314 }
  315 + failure?failure(error):@"";
  316 +
267 317  
  318 + }else{
  319 + failure?failure(error):@"";
  320 +
268 321 }
269 322 }];
270   -
271 323 }
272 324  
273 325 #pragma mark - 跳转控制器
274   -+ (void)pushToWebControllerUrl:(NSString *)url name:(NSString *)name {
  326 ++ (void)pushToWebControllerUrl:(NSString *)url name:(NSString *)name showCloseBtn:(BOOL)isShow{
275 327 UIViewController *root = [UIApplication sharedApplication].delegate.window.rootViewController;
276 328  
277 329 //跟控制器是Navigation
278 330 if ([root isKindOfClass:[UINavigationController class]]){
279 331 UINavigationController *nav = (UINavigationController *)root;
280   - CNLiveAgreementWebController *vc = [[CNLiveAgreementWebController alloc] initWithUrl:url name:name];
  332 + CNLiveAgreementWebController *vc = [[CNLiveAgreementWebController alloc] initWithUrl:url name:name showCloseBtn:isShow];
281 333 [nav pushViewController:vc animated:YES];
282 334  
283 335 }
... ... @@ -285,11 +337,11 @@ static CNLiveAgreementManager *_instance = nil;
285 337 else if ([root isKindOfClass:[UITabBarController class]]){
286 338 UITabBarController *tab = (UITabBarController *)root;
287 339 UINavigationController *nav = tab.selectedViewController;
288   - CNLiveAgreementWebController *vc = [[CNLiveAgreementWebController alloc] initWithUrl:url name:name];
  340 + CNLiveAgreementWebController *vc = [[CNLiveAgreementWebController alloc] initWithUrl:url name:name showCloseBtn:isShow];
289 341 [nav pushViewController:vc animated:YES];
290 342  
291 343 }else{
292   - CNLiveAgreementWebController *vc = [[CNLiveAgreementWebController alloc] initWithUrl:url name:name];
  344 + CNLiveAgreementWebController *vc = [[CNLiveAgreementWebController alloc] initWithUrl:url name:name showCloseBtn:isShow];
293 345 [root presentViewController:vc animated:YES completion:nil];
294 346  
295 347 }
... ...
CNLiveUserAgreementManager/Classes/CNLiveAgreementWebController.h
... ... @@ -11,7 +11,13 @@
11 11 NS_ASSUME_NONNULL_BEGIN
12 12  
13 13 @interface CNLiveAgreementWebController : UIViewController
14   -- (instancetype)initWithUrl:(NSString *)url name:(NSString *)name;
  14 +/**
  15 + * 对象方法 初始化方法
  16 + * @param url url
  17 + * @param name 标题
  18 + * @param isShow 是否显示关闭按钮
  19 + */
  20 +- (instancetype)initWithUrl:(NSString *)url name:(NSString *)name showCloseBtn:(BOOL)isShow;
15 21  
16 22 @end
17 23  
... ...
CNLiveUserAgreementManager/Classes/CNLiveAgreementWebController.m
... ... @@ -12,6 +12,8 @@
12 12 @interface CNLiveAgreementWebController ()<WKUIDelegate, WKNavigationDelegate>
13 13 @property (nonatomic, copy) NSString *url;
14 14 @property (nonatomic, copy) NSString *name;
  15 +@property (nonatomic, assign) BOOL isShow;
  16 +
15 17 @property (nonatomic, strong) WKWebView *webView;
16 18 @property (nonatomic, strong) UIProgressView *processView;
17 19 @property (nonatomic, weak) UILabel *titleLabel;
... ... @@ -20,11 +22,12 @@
20 22  
21 23 @implementation CNLiveAgreementWebController
22 24  
23   -- (instancetype)initWithUrl:(NSString *)url name:(NSString *)name {
  25 +- (instancetype)initWithUrl:(NSString *)url name:(NSString *)name showCloseBtn:(BOOL)isShow {
24 26 self = [super init];
25 27 if (self) {
26 28 self.url = url;
27 29 self.name = name;
  30 + self.isShow = isShow;
28 31 }
29 32 return self;
30 33 }
... ... @@ -93,12 +96,19 @@
93 96  
94 97 UIButton *leftBtn = [UIButton buttonWithType:UIButtonTypeSystem];
95 98 leftBtn.frame = CGRectMake(0, 0, 44, 44);
96   - UIImage *image = [self xw_getImageName:@"web_black_back" bundle:@"CNLiveAgreementManager.bundle/CNLiveAgreementManager" targetClass:[CNLiveAgreementWebController class]];
97   - [leftBtn setImage:[image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
98   -// [leftBtn setContentHorizontalAlignment:UIControlContentHorizontalAlignmentRight];
  99 + UIImage *leftImage = [self xw_getImageName:@"web_black_back" bundle:@"CNLiveAgreementManager.bundle/CNLiveAgreementManager" targetClass:[CNLiveAgreementWebController class]];
  100 + [leftBtn setImage:[leftImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
99 101 [leftBtn addTarget:self action:@selector(goBack) forControlEvents:UIControlEventTouchUpInside];
100 102 [navView addSubview:leftBtn];
101 103  
  104 + UIButton *closeBtn = [UIButton buttonWithType:UIButtonTypeSystem];
  105 + closeBtn.frame = CGRectMake(44, 0, 44, 44);
  106 + UIImage *closeImage = [self xw_getImageName:@"web_black_close" bundle:@"CNLiveAgreementManager.bundle/CNLiveAgreementManager" targetClass:[CNLiveAgreementWebController class]];
  107 + [closeBtn setImage:[closeImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
  108 + [closeBtn addTarget:self action:@selector(closeClick) forControlEvents:UIControlEventTouchUpInside];
  109 + closeBtn.hidden = !self.isShow;
  110 + [navView addSubview:closeBtn];
  111 +
102 112 UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(([[UIScreen mainScreen] bounds].size.width - 200)/2.0, 0, 200, 44)];
103 113 titleLabel.font = [UIFont boldSystemFontOfSize:17];
104 114 titleLabel.textColor = [UIColor blackColor];
... ...
Example/CNLiveUserAgreementManager/CNLiveAppDelegate.m
... ... @@ -7,12 +7,18 @@
7 7 //
8 8  
9 9 #import "CNLiveAppDelegate.h"
  10 +#import "CNLiveViewController.h"
10 11  
11 12 @implementation CNLiveAppDelegate
12 13  
13 14 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
14 15 {
15 16 // Override point for customization after application launch.
  17 + UINavigationController *navCtrl = [[UINavigationController alloc] initWithRootViewController:[CNLiveViewController new]];
  18 +
  19 + self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
  20 + self.window.rootViewController = navCtrl;
  21 + [self.window makeKeyAndVisible];
16 22 return YES;
17 23 }
18 24  
... ...
Example/CNLiveUserAgreementManager/CNLiveViewController.m
... ... @@ -8,6 +8,7 @@
8 8  
9 9 #import "CNLiveViewController.h"
10 10 #import "CNLiveAgreementManager.h"
  11 +#import "CNLiveEnvironment.h"
11 12  
12 13 @interface CNLiveViewController ()
13 14  
... ... @@ -20,6 +21,8 @@
20 21 [super viewDidLoad];
21 22 // Do any additional setup after loading the view, typically from a nib.
22 23  
  24 + [CNLiveEnvironmentManager setEnvironment:CNLiveDebugAppStore];
  25 + self.view.backgroundColor = [UIColor whiteColor];
23 26 UIButton *btn0 = [UIButton buttonWithType:UIButtonTypeCustom];
24 27 btn0.frame = CGRectMake(0, 0, 100, 100);
25 28 btn0.center = self.view.center;
... ... @@ -28,13 +31,6 @@
28 31 [btn0 addTarget:self action:@selector(testButtonClicked) forControlEvents:UIControlEventTouchUpInside];
29 32 [self.view addSubview:btn0];
30 33  
31   -// [CNLiveAgreementManager getAgreementH5WithType:CNAgreementUser success:^(NSString * _Nonnull h5, NSString * _Nonnull title) {
32   -// NSLog(@"%@",h5);
33   -// NSLog(@"%@",title);
34   -//
35   -// } failure:^(NSError * _Nonnull error) {
36   -//
37   -// }];
38 34 }
39 35 - (void)testButtonClicked {
40 36 // [CNLiveAgreementManager jumpToAgreementH5WithType:CNAgreementUser];
... ...