Commit a9ba6408f798d4275988de9ea4a0ebff4a20dc64
1 parent
9908d894
no message
Showing
7 changed files
with
189 additions
and
50 deletions
CNLiveUserAgreementManager.podspec
| ... | ... | @@ -38,7 +38,8 @@ TODO: Add long description of the pod here. |
| 38 | 38 | |
| 39 | 39 | s.public_header_files = 'CNLiveUserAgreementManager/Classes/**/*.h' |
| 40 | 40 | # s.frameworks = 'UIKit', 'MapKit' |
| 41 | - # s.dependency 'AFNetworking', '~> 2.3' | |
| 41 | + # | |
| 42 | + s.dependency 'WebViewJavascriptBridge' | |
| 42 | 43 | s.dependency 'CNLiveRequestBastKit' |
| 43 | 44 | s.dependency 'CNLiveEnvironment' |
| 44 | 45 | ... | ... |
CNLiveUserAgreementManager/Classes/CNLiveAgreementManager.h
| ... | ... | @@ -9,7 +9,8 @@ |
| 9 | 9 | #import <Foundation/Foundation.h> |
| 10 | 10 | |
| 11 | 11 | NS_ASSUME_NONNULL_BEGIN |
| 12 | -typedef enum { | |
| 12 | + | |
| 13 | +typedef NS_ENUM(NSUInteger, CNGetAgreementH5Type) { | |
| 13 | 14 | CNAgreementUser = 1001,//用户协议 |
| 14 | 15 | CNAgreementPrivacy = 1002,//隐私政策 |
| 15 | 16 | CNAgreementHelp = 1003,//帮助与反馈 |
| ... | ... | @@ -24,11 +25,11 @@ typedef enum { |
| 24 | 25 | CNAgreementEmojiService = 1012,//表情包服务说明 |
| 25 | 26 | CNAgreementEmojiComplaints = 1013,//表情包投诉说明 |
| 26 | 27 | CNAgreementEnterpriseQualification = 1014,//企业资质 |
| 27 | - CNAgreementBuyAudio = 1015,//购买音频协议 | |
| 28 | + CNAgreementBuyAudio = 1015 //购买音频协议 | |
| 28 | 29 | |
| 29 | -} CNGetAgreementH5Type; | |
| 30 | +}; | |
| 30 | 31 | |
| 31 | -typedef void(^SuccessBlock)(NSString *h5, NSString *title); | |
| 32 | +typedef void(^SuccessBlock)(NSString *h5, NSString *title, BOOL isShow); | |
| 32 | 33 | typedef void(^FailureBlock)(NSError *error); |
| 33 | 34 | |
| 34 | 35 | @interface CNLiveAgreementManager : NSObject | ... | ... |
CNLiveUserAgreementManager/Classes/CNLiveAgreementManager.m
| ... | ... | @@ -29,7 +29,6 @@ static CNLiveAgreementManager *_instance = nil; |
| 29 | 29 | _instance = [[CNLiveAgreementManager alloc]init]; |
| 30 | 30 | }); |
| 31 | 31 | return _instance; |
| 32 | - | |
| 33 | 32 | } |
| 34 | 33 | |
| 35 | 34 | + (id)allocWithZone:(struct _NSZone *)zone{ |
| ... | ... | @@ -73,7 +72,7 @@ static CNLiveAgreementManager *_instance = nil; |
| 73 | 72 | { |
| 74 | 73 | if ([[NSString stringWithFormat:@"%@",dic[@"type"]] isEqualToString:@"yhxy"]) { |
| 75 | 74 | if (success) { |
| 76 | - success(dic[@"detailUrl"],dic[@"title"]); | |
| 75 | + success(dic[@"detailUrl"], dic[@"title"], YES); | |
| 77 | 76 | return ; |
| 78 | 77 | } |
| 79 | 78 | } |
| ... | ... | @@ -83,7 +82,7 @@ static CNLiveAgreementManager *_instance = nil; |
| 83 | 82 | { |
| 84 | 83 | if ([[NSString stringWithFormat:@"%@",dic[@"type"]] isEqualToString:@"yszc"]) { |
| 85 | 84 | if (success) { |
| 86 | - success(dic[@"detailUrl"],dic[@"title"]); | |
| 85 | + success(dic[@"detailUrl"], dic[@"title"], YES); | |
| 87 | 86 | return ; |
| 88 | 87 | } |
| 89 | 88 | } |
| ... | ... | @@ -93,7 +92,7 @@ static CNLiveAgreementManager *_instance = nil; |
| 93 | 92 | { |
| 94 | 93 | if ([[NSString stringWithFormat:@"%@",dic[@"type"]] isEqualToString:@"bzfk"]) { |
| 95 | 94 | if (success) { |
| 96 | - success(dic[@"detailUrl"],dic[@"title"]); | |
| 95 | + success(dic[@"detailUrl"], dic[@"title"], YES); | |
| 97 | 96 | return ; |
| 98 | 97 | } |
| 99 | 98 | } |
| ... | ... | @@ -103,7 +102,7 @@ static CNLiveAgreementManager *_instance = nil; |
| 103 | 102 | { |
| 104 | 103 | if ([[NSString stringWithFormat:@"%@",dic[@"type"]] isEqualToString:@"ljwjj"]) { |
| 105 | 104 | if (success) { |
| 106 | - success(dic[@"detailUrl"],dic[@"title"]); | |
| 105 | + success(dic[@"detailUrl"], dic[@"title"], YES); | |
| 107 | 106 | return ; |
| 108 | 107 | } |
| 109 | 108 | } |
| ... | ... | @@ -111,9 +110,9 @@ static CNLiveAgreementManager *_instance = nil; |
| 111 | 110 | break; |
| 112 | 111 | case CNAgreementIntroduction: |
| 113 | 112 | { |
| 114 | - if ([[NSString stringWithFormat:@"%@",dic[@"type"]] isEqualToString:@"yyjj"]) { | |
| 113 | + if ([[NSString stringWithFormat:@"%@", dic[@"type"]] isEqualToString:@"yyjj"]) { | |
| 115 | 114 | if (success) { |
| 116 | - success(dic[@"detailUrl"],dic[@"title"]); | |
| 115 | + success(dic[@"detailUrl"], dic[@"title"], YES); | |
| 117 | 116 | return ; |
| 118 | 117 | } |
| 119 | 118 | } |
| ... | ... | @@ -121,9 +120,9 @@ static CNLiveAgreementManager *_instance = nil; |
| 121 | 120 | break; |
| 122 | 121 | case CNAgreementCopyright: |
| 123 | 122 | { |
| 124 | - if ([[NSString stringWithFormat:@"%@",dic[@"type"]] isEqualToString:@"bqxx"]) { | |
| 123 | + if ([[NSString stringWithFormat:@"%@", dic[@"type"]] isEqualToString:@"bqxx"]) { | |
| 125 | 124 | if (success) { |
| 126 | - success(dic[@"detailUrl"],dic[@"title"]); | |
| 125 | + success(dic[@"detailUrl"], dic[@"title"], YES); | |
| 127 | 126 | return ; |
| 128 | 127 | } |
| 129 | 128 | } |
| ... | ... | @@ -131,9 +130,9 @@ static CNLiveAgreementManager *_instance = nil; |
| 131 | 130 | break; |
| 132 | 131 | case CNAgreementPermission: |
| 133 | 132 | { |
| 134 | - if ([[NSString stringWithFormat:@"%@",dic[@"type"]] isEqualToString:@"rjxkxy"]) { | |
| 133 | + if ([[NSString stringWithFormat:@"%@", dic[@"type"]] isEqualToString:@"rjxkxy"]) { | |
| 135 | 134 | if (success) { |
| 136 | - success(dic[@"detailUrl"],dic[@"title"]); | |
| 135 | + success(dic[@"detailUrl"], dic[@"title"], YES); | |
| 137 | 136 | return ; |
| 138 | 137 | } |
| 139 | 138 | } |
| ... | ... | @@ -141,9 +140,9 @@ static CNLiveAgreementManager *_instance = nil; |
| 141 | 140 | break; |
| 142 | 141 | case CNAgreementIntegralRules: |
| 143 | 142 | { |
| 144 | - if ([[NSString stringWithFormat:@"%@",dic[@"type"]] isEqualToString:@"jfgz"]) { | |
| 143 | + if ([[NSString stringWithFormat:@"%@", dic[@"type"]] isEqualToString:@"jfgz"]) { | |
| 145 | 144 | if (success) { |
| 146 | - success(dic[@"detailUrl"],dic[@"title"]); | |
| 145 | + success(dic[@"detailUrl"], dic[@"title"], YES); | |
| 147 | 146 | return ; |
| 148 | 147 | } |
| 149 | 148 | } |
| ... | ... | @@ -151,9 +150,9 @@ static CNLiveAgreementManager *_instance = nil; |
| 151 | 150 | break; |
| 152 | 151 | case CNAgreementSigninRules: |
| 153 | 152 | { |
| 154 | - if ([[NSString stringWithFormat:@"%@",dic[@"type"]] isEqualToString:@"jfjlgz"]) { | |
| 153 | + if ([[NSString stringWithFormat:@"%@", dic[@"type"]] isEqualToString:@"jfjlgz"]) { | |
| 155 | 154 | if (success) { |
| 156 | - success(dic[@"detailUrl"],dic[@"title"]); | |
| 155 | + success(dic[@"detailUrl"], dic[@"title"], YES); | |
| 157 | 156 | return ; |
| 158 | 157 | } |
| 159 | 158 | } |
| ... | ... | @@ -161,9 +160,9 @@ static CNLiveAgreementManager *_instance = nil; |
| 161 | 160 | break; |
| 162 | 161 | case CNAgreementReviewApply: |
| 163 | 162 | { |
| 164 | - if ([[NSString stringWithFormat:@"%@",dic[@"type"]] isEqualToString:@"shsqxy"]) { | |
| 163 | + if ([[NSString stringWithFormat:@"%@", dic[@"type"]] isEqualToString:@"shsqxy"]) { | |
| 165 | 164 | if (success) { |
| 166 | - success(dic[@"detailUrl"],dic[@"title"]); | |
| 165 | + success(dic[@"detailUrl"], dic[@"title"], YES); | |
| 167 | 166 | return ; |
| 168 | 167 | } |
| 169 | 168 | } |
| ... | ... | @@ -171,9 +170,9 @@ static CNLiveAgreementManager *_instance = nil; |
| 171 | 170 | break; |
| 172 | 171 | case CNAgreementCancellation: |
| 173 | 172 | { |
| 174 | - if ([[NSString stringWithFormat:@"%@",dic[@"type"]] isEqualToString:@"zxxz"]) { | |
| 173 | + if ([[NSString stringWithFormat:@"%@", dic[@"type"]] isEqualToString:@"zxxz"]) { | |
| 175 | 174 | if (success) { |
| 176 | - success(dic[@"detailUrl"],dic[@"title"]); | |
| 175 | + success(dic[@"detailUrl"], dic[@"title"], YES); | |
| 177 | 176 | return ; |
| 178 | 177 | } |
| 179 | 178 | } |
| ... | ... | @@ -181,9 +180,9 @@ static CNLiveAgreementManager *_instance = nil; |
| 181 | 180 | break; |
| 182 | 181 | case CNAgreementEmojiService: |
| 183 | 182 | { |
| 184 | - if ([[NSString stringWithFormat:@"%@",dic[@"type"]] isEqualToString:@"fwsm"]) { | |
| 183 | + if ([[NSString stringWithFormat:@"%@", dic[@"type"]] isEqualToString:@"fwsm"]) { | |
| 185 | 184 | if (success) { |
| 186 | - success(dic[@"detailUrl"],dic[@"title"]); | |
| 185 | + success(dic[@"detailUrl"], dic[@"title"], YES); | |
| 187 | 186 | return ; |
| 188 | 187 | } |
| 189 | 188 | } |
| ... | ... | @@ -191,9 +190,9 @@ static CNLiveAgreementManager *_instance = nil; |
| 191 | 190 | break; |
| 192 | 191 | case CNAgreementEmojiComplaints: |
| 193 | 192 | { |
| 194 | - if ([[NSString stringWithFormat:@"%@",dic[@"type"]] isEqualToString:@"tssm"]) { | |
| 193 | + if ([[NSString stringWithFormat:@"%@", dic[@"type"]] isEqualToString:@"tssm"]) { | |
| 195 | 194 | if (success) { |
| 196 | - success(dic[@"detailUrl"],dic[@"title"]); | |
| 195 | + success(dic[@"detailUrl"], dic[@"title"], YES); | |
| 197 | 196 | return ; |
| 198 | 197 | } |
| 199 | 198 | } |
| ... | ... | @@ -201,9 +200,9 @@ static CNLiveAgreementManager *_instance = nil; |
| 201 | 200 | break; |
| 202 | 201 | case CNAgreementEnterpriseQualification: |
| 203 | 202 | { |
| 204 | - if ([[NSString stringWithFormat:@"%@",dic[@"type"]] isEqualToString:@"qyzz"]) { | |
| 203 | + if ([[NSString stringWithFormat:@"%@", dic[@"type"]] isEqualToString:@"qyzz"]) { | |
| 205 | 204 | if (success) { |
| 206 | - success(dic[@"detailUrl"],dic[@"title"]); | |
| 205 | + success(dic[@"detailUrl"], dic[@"title"], YES); | |
| 207 | 206 | return ; |
| 208 | 207 | } |
| 209 | 208 | } |
| ... | ... | @@ -211,9 +210,9 @@ static CNLiveAgreementManager *_instance = nil; |
| 211 | 210 | break; |
| 212 | 211 | case CNAgreementBuyAudio: |
| 213 | 212 | { |
| 214 | - if ([[NSString stringWithFormat:@"%@",dic[@"type"]] isEqualToString:@"ypxy"]) { | |
| 213 | + if ([[NSString stringWithFormat:@"%@", dic[@"type"]] isEqualToString:@"ypxy"]) { | |
| 215 | 214 | if (success) { |
| 216 | - success(dic[@"detailUrl"],dic[@"title"]); | |
| 215 | + success(dic[@"detailUrl"], dic[@"title"], YES); | |
| 217 | 216 | return ; |
| 218 | 217 | } |
| 219 | 218 | } |
| ... | ... | @@ -241,8 +240,8 @@ static CNLiveAgreementManager *_instance = nil; |
| 241 | 240 | * @param failure 请求失败回调 |
| 242 | 241 | */ |
| 243 | 242 | + (void)getAgreementH5WithType:(CNGetAgreementH5Type)type success:(SuccessBlock)success failure:(FailureBlock)failure { |
| 244 | - [[CNLiveAgreementManager manager] getAgreementH5WithType:type success:^(NSString * _Nonnull h5, NSString * _Nonnull title) { | |
| 245 | - success?success(h5, title):@""; | |
| 243 | + [[CNLiveAgreementManager manager] getAgreementH5WithType:type success:^(NSString * _Nonnull h5, NSString * _Nonnull title, BOOL isShow) { | |
| 244 | + success?success(h5, title, isShow):@""; | |
| 246 | 245 | |
| 247 | 246 | } failure:^(NSError * _Nonnull error) { |
| 248 | 247 | failure?failure(error):@""; |
| ... | ... | @@ -257,10 +256,10 @@ static CNLiveAgreementManager *_instance = nil; |
| 257 | 256 | */ |
| 258 | 257 | + (void)jumpToAgreementH5WithType:(CNGetAgreementH5Type)type{ |
| 259 | 258 | __weak typeof(self) weakSelf = self; |
| 260 | - [CNLiveAgreementManager getAgreementH5WithType:type success:^(NSString *h5, NSString *title) { | |
| 259 | + [CNLiveAgreementManager getAgreementH5WithType:type success:^(NSString *h5, NSString *title, BOOL isShow) { | |
| 261 | 260 | __strong typeof(weakSelf) strongSelf = weakSelf; |
| 262 | 261 | if(!strongSelf) return; |
| 263 | - [strongSelf pushToWebControllerUrl:h5 name:title showCloseBtn:YES]; | |
| 262 | + [strongSelf pushToWebControllerUrl:h5 name:title showCloseBtn:isShow]; | |
| 264 | 263 | |
| 265 | 264 | } failure:^(NSError *error) { |
| 266 | 265 | if(TestEnvironment){ |
| ... | ... | @@ -278,10 +277,10 @@ static CNLiveAgreementManager *_instance = nil; |
| 278 | 277 | */ |
| 279 | 278 | + (void)jumpToAgreementH5WithString:(NSString *)string { |
| 280 | 279 | __weak typeof(self) weakSelf = self; |
| 281 | - [CNLiveAgreementManager getAgreementH5WithString:string success:^(NSString *h5, NSString *title) { | |
| 280 | + [CNLiveAgreementManager getAgreementH5WithString:string success:^(NSString *h5, NSString *title, BOOL isShow) { | |
| 282 | 281 | __strong typeof(weakSelf) strongSelf = weakSelf; |
| 283 | 282 | if(!strongSelf) return; |
| 284 | - [strongSelf pushToWebControllerUrl:h5 name:title showCloseBtn:NO]; | |
| 283 | + [strongSelf pushToWebControllerUrl:h5 name:title showCloseBtn:isShow]; | |
| 285 | 284 | |
| 286 | 285 | } failure:^(NSError *error) { |
| 287 | 286 | if(TestEnvironment){ |
| ... | ... | @@ -299,8 +298,8 @@ static CNLiveAgreementManager *_instance = nil; |
| 299 | 298 | * @param failure 请求失败回调 |
| 300 | 299 | */ |
| 301 | 300 | + (void)getAgreementH5WithString:(NSString *)string success:(SuccessBlock)success failure:(FailureBlock)failure{ |
| 302 | - [[CNLiveAgreementManager manager] getAgreementH5WithString:string success:^(NSString *h5, NSString *title) { | |
| 303 | - success?success(h5, title):@""; | |
| 301 | + [[CNLiveAgreementManager manager] getAgreementH5WithString:string success:^(NSString *h5, NSString *title, BOOL isShow) { | |
| 302 | + success?success(h5, title, isShow):@""; | |
| 304 | 303 | |
| 305 | 304 | } failure:^(NSError *error) { |
| 306 | 305 | failure?failure(error):@""; |
| ... | ... | @@ -321,7 +320,7 @@ static CNLiveAgreementManager *_instance = nil; |
| 321 | 320 | if ([responseObject isKindOfClass:[NSArray class]]) { |
| 322 | 321 | for (NSDictionary *dic in responseObject) { |
| 323 | 322 | if ([[NSString stringWithFormat:@"%@",dic[@"type"]] isEqualToString:string]) { |
| 324 | - success?success(dic[@"detailUrl"], dic[@"title"]):@""; | |
| 323 | + success?success(dic[@"detailUrl"], dic[@"title"], YES):@""; | |
| 325 | 324 | return; |
| 326 | 325 | } |
| 327 | 326 | ... | ... |
CNLiveUserAgreementManager/Classes/CNLiveAgreementWebController.h
| ... | ... | @@ -17,7 +17,7 @@ NS_ASSUME_NONNULL_BEGIN |
| 17 | 17 | * @param name 标题 |
| 18 | 18 | * @param isShow 是否显示关闭按钮 |
| 19 | 19 | */ |
| 20 | -- (instancetype)initWithUrl:(NSString *)url name:(NSString *)name showCloseBtn:(BOOL)isShow; | |
| 20 | +- (instancetype)initWithUrl:(NSString *)url name:(nullable NSString *)name showCloseBtn:(BOOL)isShow; | |
| 21 | 21 | |
| 22 | 22 | @end |
| 23 | 23 | ... | ... |
CNLiveUserAgreementManager/Classes/CNLiveAgreementWebController.m
| ... | ... | @@ -7,13 +7,16 @@ |
| 7 | 7 | // |
| 8 | 8 | |
| 9 | 9 | #import "CNLiveAgreementWebController.h" |
| 10 | +#import "WKWebViewJavascriptBridge.h" | |
| 10 | 11 | #import <WebKit/WebKit.h> |
| 12 | +#import "CNLiveEnvironment.h" | |
| 11 | 13 | |
| 12 | 14 | @interface CNLiveAgreementWebController ()<WKUIDelegate, WKNavigationDelegate> |
| 13 | 15 | @property (nonatomic, copy) NSString *url; |
| 14 | 16 | @property (nonatomic, copy) NSString *name; |
| 15 | 17 | @property (nonatomic, assign) BOOL isShow; |
| 16 | 18 | |
| 19 | +@property (nonatomic, strong) WKWebViewJavascriptBridge *bridge; | |
| 17 | 20 | @property (nonatomic, strong) WKWebView *webView; |
| 18 | 21 | @property (nonatomic, strong) UIProgressView *processView; |
| 19 | 22 | @property (nonatomic, weak) UILabel *titleLabel; |
| ... | ... | @@ -21,8 +24,8 @@ |
| 21 | 24 | @end |
| 22 | 25 | |
| 23 | 26 | @implementation CNLiveAgreementWebController |
| 24 | - | |
| 25 | -- (instancetype)initWithUrl:(NSString *)url name:(NSString *)name showCloseBtn:(BOOL)isShow { | |
| 27 | +#pragma mark - 初始化方法 | |
| 28 | +- (instancetype)initWithUrl:(NSString *)url name:(nullable NSString *)name showCloseBtn:(BOOL)isShow { | |
| 26 | 29 | self = [super init]; |
| 27 | 30 | if (self) { |
| 28 | 31 | self.url = url; |
| ... | ... | @@ -69,12 +72,17 @@ |
| 69 | 72 | } |
| 70 | 73 | [self setupNavigationBar]; |
| 71 | 74 | [self setupUI]; |
| 75 | + [self setupUserAgent]; | |
| 76 | + [self interaction]; | |
| 72 | 77 | [self loadUrl]; |
| 73 | 78 | |
| 74 | 79 | } |
| 75 | 80 | |
| 76 | 81 | - (void)dealloc { |
| 77 | - NSLog(@"CNUserAgreementWebController dealloc"); | |
| 82 | + if(TestEnvironment){ | |
| 83 | + NSLog(@"CNUserAgreementWebController dealloc"); | |
| 84 | + | |
| 85 | + } | |
| 78 | 86 | [self.webView stopLoading]; |
| 79 | 87 | [self.webView removeObserver:self forKeyPath:@"estimatedProgress"]; |
| 80 | 88 | if (!self.name) { |
| ... | ... | @@ -87,6 +95,107 @@ |
| 87 | 95 | |
| 88 | 96 | } |
| 89 | 97 | |
| 98 | +#pragma mark - 交互相关 | |
| 99 | +- (void)interaction { | |
| 100 | + [WKWebViewJavascriptBridge enableLogging]; | |
| 101 | + self.bridge = [WKWebViewJavascriptBridge bridgeForWebView:self.webView]; | |
| 102 | + [self.bridge setWebViewDelegate:self]; | |
| 103 | + | |
| 104 | + __weak typeof(self) weakSelf = self; | |
| 105 | + | |
| 106 | + // 帮助与反馈->产品建议:添加照片按钮 | |
| 107 | + [self.bridge registerHandler:@"wjjHelpAndFeedbackImage" handler:^(id data, WVJBResponseCallback responseCallback) { | |
| 108 | + if(TestEnvironment){ | |
| 109 | + NSLog(@"ObjC Echo called with: %@", data); | |
| 110 | + | |
| 111 | + } | |
| 112 | + __strong typeof(weakSelf) strongSelf = weakSelf; | |
| 113 | + if(strongSelf){ | |
| 114 | + | |
| 115 | + } | |
| 116 | + responseCallback(data); | |
| 117 | + }]; | |
| 118 | + | |
| 119 | + // 帮助与反馈->产品建议:删除照片 | |
| 120 | + [self.bridge registerHandler:@"wjjDelegateImage" handler:^(id data, WVJBResponseCallback responseCallback) { | |
| 121 | + if(TestEnvironment){ | |
| 122 | + NSLog(@"ObjC Echo called with: %@", data); | |
| 123 | + | |
| 124 | + } | |
| 125 | + __strong typeof(weakSelf) strongSelf = weakSelf; | |
| 126 | + if(strongSelf){ | |
| 127 | + | |
| 128 | + } | |
| 129 | + responseCallback(data); | |
| 130 | + }]; | |
| 131 | + | |
| 132 | + // 帮助与反馈->产品建议:点击提交 | |
| 133 | + [self.bridge registerHandler:@"wjjSubmitImage" handler:^(id data, WVJBResponseCallback responseCallback) { | |
| 134 | + if(TestEnvironment){ | |
| 135 | + NSLog(@"ObjC Echo called with: %@", data); | |
| 136 | + | |
| 137 | + } | |
| 138 | + __strong typeof(weakSelf) strongSelf = weakSelf; | |
| 139 | + if(strongSelf){ | |
| 140 | + | |
| 141 | + } | |
| 142 | + responseCallback(data); | |
| 143 | + }]; | |
| 144 | + | |
| 145 | + // 反馈提交(成功/失败)后隐藏loading | |
| 146 | + [self.bridge registerHandler:@"wjjSubmitSuccessFinal" handler:^(id data, WVJBResponseCallback responseCallback) { | |
| 147 | + if(TestEnvironment){ | |
| 148 | + NSLog(@"ObjC Echo called with: %@", data); | |
| 149 | + | |
| 150 | + } | |
| 151 | + __strong typeof(weakSelf) strongSelf = weakSelf; | |
| 152 | + if(strongSelf){ | |
| 153 | + | |
| 154 | + } | |
| 155 | + responseCallback(data); | |
| 156 | + }]; | |
| 157 | + | |
| 158 | + // 帮助与反馈 提交反馈后点击完成 | |
| 159 | + [self.bridge registerHandler:@"wjjFeedbackSuccess" handler:^(id data, WVJBResponseCallback responseCallback) { | |
| 160 | + if(TestEnvironment){ | |
| 161 | + NSLog(@"ObjC Echo called with: %@", data); | |
| 162 | + | |
| 163 | + } | |
| 164 | + __strong typeof(weakSelf) strongSelf = weakSelf; | |
| 165 | + if(strongSelf){ | |
| 166 | + | |
| 167 | + } | |
| 168 | + responseCallback(data); | |
| 169 | + }]; | |
| 170 | + | |
| 171 | + // h5主动从客户端获取网络状态 | |
| 172 | + [self.bridge registerHandler:@"wjjJSGetNetStatusFromClient" handler:^(id data, WVJBResponseCallback responseCallback) { | |
| 173 | + if(TestEnvironment){ | |
| 174 | + NSLog(@"ObjC Echo called with: %@", data); | |
| 175 | + | |
| 176 | + } | |
| 177 | + __strong typeof(weakSelf) strongSelf = weakSelf; | |
| 178 | + if(strongSelf){ | |
| 179 | + | |
| 180 | + } | |
| 181 | + responseCallback(data); | |
| 182 | + }]; | |
| 183 | + | |
| 184 | + // 原生直播/回放无网络时的提示 | |
| 185 | + [self.bridge registerHandler:@"wjjClickLiveOnLine" handler:^(id data, WVJBResponseCallback responseCallback) { | |
| 186 | + if(TestEnvironment){ | |
| 187 | + NSLog(@"ObjC Echo called with: %@", data); | |
| 188 | + | |
| 189 | + } | |
| 190 | + __strong typeof(weakSelf) strongSelf = weakSelf; | |
| 191 | + if(strongSelf){ | |
| 192 | + | |
| 193 | + } | |
| 194 | + responseCallback(data); | |
| 195 | + }]; | |
| 196 | + | |
| 197 | +} | |
| 198 | + | |
| 90 | 199 | #pragma mark - 创建导航条 |
| 91 | 200 | - (void)setupNavigationBar { |
| 92 | 201 | UIView *navView = [[UIView alloc] initWithFrame:CGRectMake(0, [UIApplication sharedApplication].statusBarFrame.size.height, [UIScreen mainScreen].bounds.size.width, 44)]; |
| ... | ... | @@ -135,15 +244,41 @@ |
| 135 | 244 | [self.view addSubview:self.webView]; |
| 136 | 245 | |
| 137 | 246 | self.processView = [[UIProgressView alloc] initWithFrame:CGRectMake(0, ([UIApplication sharedApplication].statusBarFrame.size.height+44)+0.5, [[UIScreen mainScreen] bounds].size.width, 1)]; |
| 138 | - _processView.progressTintColor = [UIColor colorWithRed:0.0 green:1.0 blue:0.0 alpha:1.0]; | |
| 247 | + _processView.progressTintColor = [UIColor colorWithRed:19/255.0 green:204/255.0 blue:12/255.0 alpha:1.0]; | |
| 139 | 248 | _processView.trackTintColor = [UIColor whiteColor]; |
| 140 | 249 | [self.view addSubview:self.processView]; |
| 141 | 250 | |
| 251 | +} | |
| 252 | + | |
| 253 | +- (void)setupUserAgent { | |
| 254 | + NSString *customUserAgent = @";app/plat_a"; | |
| 255 | + | |
| 256 | + if (@available(iOS 12.0, *)) { | |
| 257 | + UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectZero]; | |
| 258 | + NSString *userAgent = [webView stringByEvaluatingJavaScriptFromString:@"navigator.userAgent"]; | |
| 259 | + NSString *newUserAgent = [userAgent stringByAppendingString:customUserAgent];//自定义需要拼接的字符串 | |
| 260 | + NSDictionary *dictionary = [NSDictionary dictionaryWithObjectsAndKeys:newUserAgent, @"UserAgent", nil]; | |
| 261 | + | |
| 262 | + [self.webView setCustomUserAgent:newUserAgent]; | |
| 263 | + [[NSUserDefaults standardUserDefaults] registerDefaults:dictionary]; | |
| 264 | + } | |
| 265 | + | |
| 266 | + __weak typeof(self) weakSelf = self; | |
| 267 | + [self.webView evaluateJavaScript:@"navigator.userAgent" completionHandler:^(id result, NSError *error) { | |
| 268 | + __strong typeof(weakSelf) strongSelf = weakSelf; | |
| 269 | + NSString *userAgent = result; | |
| 270 | + NSString *newUserAgent = [userAgent stringByAppendingString:customUserAgent]; | |
| 271 | + NSDictionary *dictionary = [NSDictionary dictionaryWithObjectsAndKeys:newUserAgent, @"UserAgent", nil]; | |
| 272 | + [[NSUserDefaults standardUserDefaults] registerDefaults:dictionary]; | |
| 273 | + if (@available(iOS 9.0, *)) { | |
| 274 | + [strongSelf.webView setCustomUserAgent:newUserAgent]; | |
| 275 | + } | |
| 276 | + }]; | |
| 277 | + | |
| 142 | 278 | [self.webView addObserver:self forKeyPath:@"estimatedProgress" options:NSKeyValueObservingOptionNew context:nil]; |
| 143 | 279 | if (!self.name) { |
| 144 | 280 | [self.webView addObserver:self forKeyPath:@"title" options:NSKeyValueObservingOptionNew context:NULL]; |
| 145 | 281 | } |
| 146 | - | |
| 147 | 282 | } |
| 148 | 283 | |
| 149 | 284 | #pragma mark - WKNavigationDelegate |
| ... | ... | @@ -252,17 +387,18 @@ |
| 252 | 387 | } |
| 253 | 388 | } |
| 254 | 389 | |
| 255 | -#pragma mark - 清除缓存 | |
| 390 | +#pragma mark - 私有方法 | |
| 256 | 391 | // 清除缓存 |
| 257 | 392 | - (void)clearWKCache { |
| 258 | 393 | NSArray *types = @[WKWebsiteDataTypeDiskCache,WKWebsiteDataTypeOfflineWebApplicationCache,WKWebsiteDataTypeMemoryCache,WKWebsiteDataTypeIndexedDBDatabases,WKWebsiteDataTypeWebSQLDatabases]; |
| 259 | 394 | NSSet *websiteDataTypes = [NSSet setWithArray:types]; |
| 260 | 395 | NSDate *dateFrom = [NSDate dateWithTimeIntervalSince1970:0]; |
| 261 | 396 | [[WKWebsiteDataStore defaultDataStore] removeDataOfTypes:websiteDataTypes modifiedSince:dateFrom completionHandler:^{ |
| 262 | - NSLog(@"清楚缓存完毕"); | |
| 397 | + | |
| 263 | 398 | }]; |
| 264 | 399 | |
| 265 | 400 | } |
| 401 | + | |
| 266 | 402 | /** |
| 267 | 403 | * 创建图片 |
| 268 | 404 | * | ... | ... |
Example/CNLiveUserAgreementManager.xcodeproj/project.pbxproj
| ... | ... | @@ -310,6 +310,7 @@ |
| 310 | 310 | "${BUILT_PRODUCTS_DIR}/CNLiveEnvironment/CNLiveEnvironment.framework", |
| 311 | 311 | "${BUILT_PRODUCTS_DIR}/CNLiveRequestBastKit/CNLiveRequestBastKit.framework", |
| 312 | 312 | "${BUILT_PRODUCTS_DIR}/CNLiveUserAgreementManager/CNLiveUserAgreementManager.framework", |
| 313 | + "${BUILT_PRODUCTS_DIR}/WebViewJavascriptBridge/WebViewJavascriptBridge.framework", | |
| 313 | 314 | ); |
| 314 | 315 | name = "[CP] Embed Pods Frameworks"; |
| 315 | 316 | outputFileListPaths = ( |
| ... | ... | @@ -319,6 +320,7 @@ |
| 319 | 320 | "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/CNLiveEnvironment.framework", |
| 320 | 321 | "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/CNLiveRequestBastKit.framework", |
| 321 | 322 | "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/CNLiveUserAgreementManager.framework", |
| 323 | + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/WebViewJavascriptBridge.framework", | |
| 322 | 324 | ); |
| 323 | 325 | runOnlyForDeploymentPostprocessing = 0; |
| 324 | 326 | shellPath = /bin/sh; | ... | ... |
Example/CNLiveUserAgreementManager/CNLiveViewController.m
| ... | ... | @@ -33,7 +33,7 @@ |
| 33 | 33 | |
| 34 | 34 | } |
| 35 | 35 | - (void)testButtonClicked { |
| 36 | - [CNLiveAgreementManager jumpToAgreementH5WithType:CNAgreementUser]; | |
| 36 | + [CNLiveAgreementManager jumpToAgreementH5WithType:CNAgreementHelp]; | |
| 37 | 37 | // [CNLiveAgreementManager jumpToAgreementH5WithString:@"yhxy"]; |
| 38 | 38 | |
| 39 | 39 | } | ... | ... |