Commit ed9502424c2faa7e98d1ba35161d2fbe9336ad69
1 parent
1400df32
no message
Showing
10 changed files
with
111 additions
and
25 deletions
CNLiveUserAgreementManager/Assets/CNLiveAgreementManager.bundle/web_black_back@2x.png
CNLiveUserAgreementManager/Assets/CNLiveAgreementManager.bundle/web_black_back@3x.png
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,6 +42,22 @@ typedef void(^FailureBlock)(NSError *error); | ||
| 42 | + (void)jumpToAgreementH5WithString:(NSString *)string; | 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 | * @param type 类型 | 62 | * @param type 类型 |
| 47 | */ | 63 | */ |
CNLiveUserAgreementManager/Classes/CNLiveAgreementManager.m
| @@ -48,6 +48,7 @@ static CNLiveAgreementManager *_instance = nil; | @@ -48,6 +48,7 @@ static CNLiveAgreementManager *_instance = nil; | ||
| 48 | return _instance; | 48 | return _instance; |
| 49 | } | 49 | } |
| 50 | 50 | ||
| 51 | +#pragma mark - 类型 | ||
| 51 | - (void)getAgreementH5WithType:(CNGetAgreementH5Type)type success:(SuccessBlock)success failure:(FailureBlock)failure { | 52 | - (void)getAgreementH5WithType:(CNGetAgreementH5Type)type success:(SuccessBlock)success failure:(FailureBlock)failure { |
| 52 | [CNLiveNetworking setAllowRequestDefaultArgument:NO]; | 53 | [CNLiveNetworking setAllowRequestDefaultArgument:NO]; |
| 53 | [CNLiveNetworking requestNetworkWithMethod:CNLiveRequestMethodGET URLString:CNGetAgreementH5Url Param:@{} CacheType:CNLiveNetworkCacheTypeNetworkOnly CompletionBlock:^(NSURLSessionTask *requestTask, id responseObject, NSError *error) { | 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,55 +230,106 @@ static CNLiveAgreementManager *_instance = nil; | ||
| 229 | 230 | ||
| 230 | + (void)getAgreementH5WithType:(CNGetAgreementH5Type)type success:(SuccessBlock)success failure:(FailureBlock)failure { | 231 | + (void)getAgreementH5WithType:(CNGetAgreementH5Type)type success:(SuccessBlock)success failure:(FailureBlock)failure { |
| 231 | [[CNLiveAgreementManager manager] getAgreementH5WithType:type success:^(NSString * _Nonnull h5, NSString * _Nonnull title) { | 232 | [[CNLiveAgreementManager manager] getAgreementH5WithType:type success:^(NSString * _Nonnull h5, NSString * _Nonnull title) { |
| 232 | - success(h5, title); | 233 | + success?success(h5, title):@""; |
| 233 | 234 | ||
| 234 | } failure:^(NSError * _Nonnull error) { | 235 | } failure:^(NSError * _Nonnull error) { |
| 235 | - failure(error); | 236 | + failure?failure(error):@""; |
| 236 | 237 | ||
| 237 | }]; | 238 | }]; |
| 238 | 239 | ||
| 239 | } | 240 | } |
| 240 | 241 | ||
| 241 | + (void)jumpToAgreementH5WithType:(CNGetAgreementH5Type)type{ | 242 | + (void)jumpToAgreementH5WithType:(CNGetAgreementH5Type)type{ |
| 242 | - | 243 | + __weak typeof(self) weakSelf = self; |
| 243 | [CNLiveAgreementManager getAgreementH5WithType:type success:^(NSString *h5, NSString *title) { | 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 | } failure:^(NSError *error) { | 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 | + (void)jumpToAgreementH5WithString:(NSString *)string { | 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 | [CNLiveNetworking setAllowRequestDefaultArgument:NO]; | 302 | [CNLiveNetworking setAllowRequestDefaultArgument:NO]; |
| 255 | [CNLiveNetworking requestNetworkWithMethod:CNLiveRequestMethodGET URLString:CNGetAgreementH5Url Param:@{} CacheType:CNLiveNetworkCacheTypeNetworkOnly CompletionBlock:^(NSURLSessionTask *requestTask, id responseObject, NSError *error) { | 303 | [CNLiveNetworking requestNetworkWithMethod:CNLiveRequestMethodGET URLString:CNGetAgreementH5Url Param:@{} CacheType:CNLiveNetworkCacheTypeNetworkOnly CompletionBlock:^(NSURLSessionTask *requestTask, id responseObject, NSError *error) { |
| 256 | if (!error) { | 304 | if (!error) { |
| 257 | if ([responseObject isKindOfClass:[NSArray class]]) { | 305 | if ([responseObject isKindOfClass:[NSArray class]]) { |
| 258 | for (NSDictionary *dic in responseObject) { | 306 | for (NSDictionary *dic in responseObject) { |
| 259 | if ([[NSString stringWithFormat:@"%@",dic[@"type"]] isEqualToString:string]) { | 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 | #pragma mark - 跳转控制器 | 325 | #pragma mark - 跳转控制器 |
| 274 | -+ (void)pushToWebControllerUrl:(NSString *)url name:(NSString *)name { | 326 | ++ (void)pushToWebControllerUrl:(NSString *)url name:(NSString *)name showCloseBtn:(BOOL)isShow{ |
| 275 | UIViewController *root = [UIApplication sharedApplication].delegate.window.rootViewController; | 327 | UIViewController *root = [UIApplication sharedApplication].delegate.window.rootViewController; |
| 276 | 328 | ||
| 277 | //跟控制器是Navigation | 329 | //跟控制器是Navigation |
| 278 | if ([root isKindOfClass:[UINavigationController class]]){ | 330 | if ([root isKindOfClass:[UINavigationController class]]){ |
| 279 | UINavigationController *nav = (UINavigationController *)root; | 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 | [nav pushViewController:vc animated:YES]; | 333 | [nav pushViewController:vc animated:YES]; |
| 282 | 334 | ||
| 283 | } | 335 | } |
| @@ -285,11 +337,11 @@ static CNLiveAgreementManager *_instance = nil; | @@ -285,11 +337,11 @@ static CNLiveAgreementManager *_instance = nil; | ||
| 285 | else if ([root isKindOfClass:[UITabBarController class]]){ | 337 | else if ([root isKindOfClass:[UITabBarController class]]){ |
| 286 | UITabBarController *tab = (UITabBarController *)root; | 338 | UITabBarController *tab = (UITabBarController *)root; |
| 287 | UINavigationController *nav = tab.selectedViewController; | 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 | [nav pushViewController:vc animated:YES]; | 341 | [nav pushViewController:vc animated:YES]; |
| 290 | 342 | ||
| 291 | }else{ | 343 | }else{ |
| 292 | - CNLiveAgreementWebController *vc = [[CNLiveAgreementWebController alloc] initWithUrl:url name:name]; | 344 | + CNLiveAgreementWebController *vc = [[CNLiveAgreementWebController alloc] initWithUrl:url name:name showCloseBtn:isShow]; |
| 293 | [root presentViewController:vc animated:YES completion:nil]; | 345 | [root presentViewController:vc animated:YES completion:nil]; |
| 294 | 346 | ||
| 295 | } | 347 | } |
CNLiveUserAgreementManager/Classes/CNLiveAgreementWebController.h
| @@ -11,7 +11,13 @@ | @@ -11,7 +11,13 @@ | ||
| 11 | NS_ASSUME_NONNULL_BEGIN | 11 | NS_ASSUME_NONNULL_BEGIN |
| 12 | 12 | ||
| 13 | @interface CNLiveAgreementWebController : UIViewController | 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 | @end | 22 | @end |
| 17 | 23 |
CNLiveUserAgreementManager/Classes/CNLiveAgreementWebController.m
| @@ -12,6 +12,8 @@ | @@ -12,6 +12,8 @@ | ||
| 12 | @interface CNLiveAgreementWebController ()<WKUIDelegate, WKNavigationDelegate> | 12 | @interface CNLiveAgreementWebController ()<WKUIDelegate, WKNavigationDelegate> |
| 13 | @property (nonatomic, copy) NSString *url; | 13 | @property (nonatomic, copy) NSString *url; |
| 14 | @property (nonatomic, copy) NSString *name; | 14 | @property (nonatomic, copy) NSString *name; |
| 15 | +@property (nonatomic, assign) BOOL isShow; | ||
| 16 | + | ||
| 15 | @property (nonatomic, strong) WKWebView *webView; | 17 | @property (nonatomic, strong) WKWebView *webView; |
| 16 | @property (nonatomic, strong) UIProgressView *processView; | 18 | @property (nonatomic, strong) UIProgressView *processView; |
| 17 | @property (nonatomic, weak) UILabel *titleLabel; | 19 | @property (nonatomic, weak) UILabel *titleLabel; |
| @@ -20,11 +22,12 @@ | @@ -20,11 +22,12 @@ | ||
| 20 | 22 | ||
| 21 | @implementation CNLiveAgreementWebController | 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 | self = [super init]; | 26 | self = [super init]; |
| 25 | if (self) { | 27 | if (self) { |
| 26 | self.url = url; | 28 | self.url = url; |
| 27 | self.name = name; | 29 | self.name = name; |
| 30 | + self.isShow = isShow; | ||
| 28 | } | 31 | } |
| 29 | return self; | 32 | return self; |
| 30 | } | 33 | } |
| @@ -93,12 +96,19 @@ | @@ -93,12 +96,19 @@ | ||
| 93 | 96 | ||
| 94 | UIButton *leftBtn = [UIButton buttonWithType:UIButtonTypeSystem]; | 97 | UIButton *leftBtn = [UIButton buttonWithType:UIButtonTypeSystem]; |
| 95 | leftBtn.frame = CGRectMake(0, 0, 44, 44); | 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 | [leftBtn addTarget:self action:@selector(goBack) forControlEvents:UIControlEventTouchUpInside]; | 101 | [leftBtn addTarget:self action:@selector(goBack) forControlEvents:UIControlEventTouchUpInside]; |
| 100 | [navView addSubview:leftBtn]; | 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 | UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(([[UIScreen mainScreen] bounds].size.width - 200)/2.0, 0, 200, 44)]; | 112 | UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(([[UIScreen mainScreen] bounds].size.width - 200)/2.0, 0, 200, 44)]; |
| 103 | titleLabel.font = [UIFont boldSystemFontOfSize:17]; | 113 | titleLabel.font = [UIFont boldSystemFontOfSize:17]; |
| 104 | titleLabel.textColor = [UIColor blackColor]; | 114 | titleLabel.textColor = [UIColor blackColor]; |
Example/CNLiveUserAgreementManager/CNLiveAppDelegate.m
| @@ -7,12 +7,18 @@ | @@ -7,12 +7,18 @@ | ||
| 7 | // | 7 | // |
| 8 | 8 | ||
| 9 | #import "CNLiveAppDelegate.h" | 9 | #import "CNLiveAppDelegate.h" |
| 10 | +#import "CNLiveViewController.h" | ||
| 10 | 11 | ||
| 11 | @implementation CNLiveAppDelegate | 12 | @implementation CNLiveAppDelegate |
| 12 | 13 | ||
| 13 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions | 14 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions |
| 14 | { | 15 | { |
| 15 | // Override point for customization after application launch. | 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 | return YES; | 22 | return YES; |
| 17 | } | 23 | } |
| 18 | 24 |
Example/CNLiveUserAgreementManager/CNLiveViewController.m
| @@ -8,6 +8,7 @@ | @@ -8,6 +8,7 @@ | ||
| 8 | 8 | ||
| 9 | #import "CNLiveViewController.h" | 9 | #import "CNLiveViewController.h" |
| 10 | #import "CNLiveAgreementManager.h" | 10 | #import "CNLiveAgreementManager.h" |
| 11 | +#import "CNLiveEnvironment.h" | ||
| 11 | 12 | ||
| 12 | @interface CNLiveViewController () | 13 | @interface CNLiveViewController () |
| 13 | 14 | ||
| @@ -20,6 +21,8 @@ | @@ -20,6 +21,8 @@ | ||
| 20 | [super viewDidLoad]; | 21 | [super viewDidLoad]; |
| 21 | // Do any additional setup after loading the view, typically from a nib. | 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 | UIButton *btn0 = [UIButton buttonWithType:UIButtonTypeCustom]; | 26 | UIButton *btn0 = [UIButton buttonWithType:UIButtonTypeCustom]; |
| 24 | btn0.frame = CGRectMake(0, 0, 100, 100); | 27 | btn0.frame = CGRectMake(0, 0, 100, 100); |
| 25 | btn0.center = self.view.center; | 28 | btn0.center = self.view.center; |
| @@ -28,13 +31,6 @@ | @@ -28,13 +31,6 @@ | ||
| 28 | [btn0 addTarget:self action:@selector(testButtonClicked) forControlEvents:UIControlEventTouchUpInside]; | 31 | [btn0 addTarget:self action:@selector(testButtonClicked) forControlEvents:UIControlEventTouchUpInside]; |
| 29 | [self.view addSubview:btn0]; | 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 | - (void)testButtonClicked { | 35 | - (void)testButtonClicked { |
| 40 | // [CNLiveAgreementManager jumpToAgreementH5WithType:CNAgreementUser]; | 36 | // [CNLiveAgreementManager jumpToAgreementH5WithType:CNAgreementUser]; |