Commit c51bb0ab17fe705583b15d0b5792d6bf9778d2b8
1 parent
91d5d51c
no message
Showing
3 changed files
with
81 additions
and
5 deletions
CNLiveUserAgreementManager.podspec
| ... | ... | @@ -38,7 +38,7 @@ 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 | - # | |
| 41 | + s.dependency 'QMUIKit' | |
| 42 | 42 | s.dependency 'WebViewJavascriptBridge' |
| 43 | 43 | s.dependency 'CNLiveRequestBastKit' |
| 44 | 44 | s.dependency 'CNLiveEnvironment' | ... | ... |
CNLiveUserAgreementManager/Classes/CNLiveAgreementWebController.m
| ... | ... | @@ -12,6 +12,8 @@ |
| 12 | 12 | #import <WebKit/WebKit.h> |
| 13 | 13 | // 环境库 |
| 14 | 14 | #import "CNLiveEnvironment.h" |
| 15 | +#import "QMUIKit.h" | |
| 16 | +#import <CNLiveRequestBastKit/CNLiveNetworking.h> | |
| 15 | 17 | |
| 16 | 18 | @interface CNLiveAgreementWebController ()<WKUIDelegate, WKNavigationDelegate> |
| 17 | 19 | @property (nonatomic, copy) NSString *url; |
| ... | ... | @@ -23,6 +25,8 @@ |
| 23 | 25 | @property (nonatomic, strong) UIProgressView *processView; |
| 24 | 26 | @property (nonatomic, weak) UILabel *titleLabel; |
| 25 | 27 | |
| 28 | +@property (nonatomic, strong) NSMutableArray *photos;// 上传图片 | |
| 29 | + | |
| 26 | 30 | @end |
| 27 | 31 | |
| 28 | 32 | @implementation CNLiveAgreementWebController |
| ... | ... | @@ -78,12 +82,13 @@ |
| 78 | 82 | [self interaction]; |
| 79 | 83 | [self loadUrl]; |
| 80 | 84 | |
| 85 | + [self getImageToken]; | |
| 86 | + | |
| 81 | 87 | } |
| 82 | 88 | |
| 83 | 89 | - (void)dealloc { |
| 84 | 90 | if(TestEnvironment){ |
| 85 | 91 | NSLog(@"CNUserAgreementWebController dealloc"); |
| 86 | - | |
| 87 | 92 | } |
| 88 | 93 | [self.webView stopLoading]; |
| 89 | 94 | [self.webView removeObserver:self forKeyPath:@"estimatedProgress"]; |
| ... | ... | @@ -124,7 +129,10 @@ |
| 124 | 129 | } |
| 125 | 130 | __strong typeof(weakSelf) strongSelf = weakSelf; |
| 126 | 131 | if(strongSelf){ |
| 127 | - | |
| 132 | + if ([data isKindOfClass:[NSDictionary class]]) { | |
| 133 | + NSInteger index = [[data objectForKey:@"index"] integerValue]; | |
| 134 | + [strongSelf.photos removeObjectAtIndex:index]; | |
| 135 | + } | |
| 128 | 136 | } |
| 129 | 137 | responseCallback(data); |
| 130 | 138 | }]; |
| ... | ... | @@ -136,6 +144,19 @@ |
| 136 | 144 | } |
| 137 | 145 | __strong typeof(weakSelf) strongSelf = weakSelf; |
| 138 | 146 | if(strongSelf){ |
| 147 | + if (strongSelf.photos.count > 0) { | |
| 148 | + [strongSelf getImageToken]; | |
| 149 | + } | |
| 150 | + else { | |
| 151 | + id data = @{ @"images": @[] }; | |
| 152 | + [QMUITips showLoading:@"正在提交" inView:weakSelf.view]; | |
| 153 | + // 帮助与反馈->产品建议App->h5图片urls | |
| 154 | + [strongSelf.bridge callHandler:@"wjjSubmitSuccess" data:data responseCallback:^(id responseData) { | |
| 155 | + if(TestEnvironment){ | |
| 156 | + NSLog(@"ObjC received response: %@", responseData); | |
| 157 | + } | |
| 158 | + }]; | |
| 159 | + } | |
| 139 | 160 | |
| 140 | 161 | } |
| 141 | 162 | responseCallback(data); |
| ... | ... | @@ -148,7 +169,8 @@ |
| 148 | 169 | } |
| 149 | 170 | __strong typeof(weakSelf) strongSelf = weakSelf; |
| 150 | 171 | if(strongSelf){ |
| 151 | - | |
| 172 | + [QMUITips hideAllToastInView:strongSelf.view animated:YES]; | |
| 173 | + | |
| 152 | 174 | } |
| 153 | 175 | responseCallback(data); |
| 154 | 176 | }]; |
| ... | ... | @@ -184,7 +206,12 @@ |
| 184 | 206 | } |
| 185 | 207 | __strong typeof(weakSelf) strongSelf = weakSelf; |
| 186 | 208 | if(strongSelf){ |
| 187 | - | |
| 209 | + NSDictionary *info = [NSDictionary dictionaryWithDictionary:data]; | |
| 210 | + if ([[info objectForKey:@"onLine"] isEqualToString:@"NONE"]) { | |
| 211 | + dispatch_async(dispatch_get_main_queue(), ^{ | |
| 212 | + [QMUITips showError:@"网络连接失败" inView:strongSelf.view hideAfterDelay:1.5]; | |
| 213 | + }); | |
| 214 | + } | |
| 188 | 215 | } |
| 189 | 216 | responseCallback(data); |
| 190 | 217 | }]; |
| ... | ... | @@ -381,6 +408,13 @@ |
| 381 | 408 | |
| 382 | 409 | } |
| 383 | 410 | } |
| 411 | +#pragma mark - 懒加载 | |
| 412 | +- (NSMutableArray *)photos{ | |
| 413 | + if(!_photos){ | |
| 414 | + _photos = [[NSMutableArray alloc]init]; | |
| 415 | + } | |
| 416 | + return _photos; | |
| 417 | +} | |
| 384 | 418 | |
| 385 | 419 | #pragma mark - 私有方法 |
| 386 | 420 | // 清除缓存 |
| ... | ... | @@ -413,4 +447,44 @@ |
| 413 | 447 | |
| 414 | 448 | } |
| 415 | 449 | |
| 450 | +#pragma mark - 上传图片到七牛 | |
| 451 | +// 获取图片的token | |
| 452 | +- (void)getImageToken { | |
| 453 | + NSDictionary *param = @{@"appId":AppId, | |
| 454 | + @"verb":@"POST", | |
| 455 | + @"storageType":@"2", | |
| 456 | + @"bucket":API_BucketName, | |
| 457 | + @"timestamp":[self currentTimestamp] | |
| 458 | + }; | |
| 459 | + [QMUITips showLoading:@"正在提交" inView:self.view]; | |
| 460 | + __weak typeof(self) weakSelf = self; | |
| 461 | + [CNLiveNetworking setAllowRequestDefaultArgument:NO]; | |
| 462 | + [CNLiveNetworking requestNetworkWithMethod:CNLiveRequestMethodPOST URLString:CNUploadAuthForApp Param:param CacheType:CNLiveNetworkCacheTypeNetworkOnly CompletionBlock:^(NSURLSessionTask *requestTask, id responseObject, NSError *error) { | |
| 463 | + __strong typeof(weakSelf) strongSelf = weakSelf; | |
| 464 | + if(!strongSelf) return ; | |
| 465 | + if ([responseObject isKindOfClass:[NSDictionary class]]) { | |
| 466 | + NSDictionary *dic = (NSDictionary *)responseObject; | |
| 467 | + if (!error && dic[@"token"] && ![dic[@"token"] isEqualToString:@""]) { | |
| 468 | +// [self QNStartUploadWithtoken:dic[@"token"]]; | |
| 469 | + return; | |
| 470 | + } | |
| 471 | + | |
| 472 | + } | |
| 473 | + [QMUITips hideAllToastInView:strongSelf.view animated:YES]; | |
| 474 | + [QMUITips showError:error.localizedDescription inView:strongSelf.view hideAfterDelay:1.5]; | |
| 475 | + | |
| 476 | + | |
| 477 | + }]; | |
| 478 | + | |
| 479 | +} | |
| 480 | + | |
| 481 | +//获取当前时间戳 | |
| 482 | +- (NSString *)currentTimestamp{ | |
| 483 | + NSDate * date = [NSDate dateWithTimeIntervalSinceNow:0];//获取当前时间0秒后的时间 | |
| 484 | + NSTimeInterval time = [date timeIntervalSince1970];// *1000 是精确到毫秒,不乘就是精确到秒 | |
| 485 | + NSString *timeString = [NSString stringWithFormat:@"%.0f", time]; | |
| 486 | + return timeString; | |
| 487 | + | |
| 488 | +} | |
| 489 | + | |
| 416 | 490 | @end | ... | ... |
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}/QMUIKit/QMUIKit.framework", | |
| 313 | 314 | "${BUILT_PRODUCTS_DIR}/WebViewJavascriptBridge/WebViewJavascriptBridge.framework", |
| 314 | 315 | ); |
| 315 | 316 | name = "[CP] Embed Pods Frameworks"; |
| ... | ... | @@ -320,6 +321,7 @@ |
| 320 | 321 | "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/CNLiveEnvironment.framework", |
| 321 | 322 | "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/CNLiveRequestBastKit.framework", |
| 322 | 323 | "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/CNLiveUserAgreementManager.framework", |
| 324 | + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/QMUIKit.framework", | |
| 323 | 325 | "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/WebViewJavascriptBridge.framework", |
| 324 | 326 | ); |
| 325 | 327 | runOnlyForDeploymentPostprocessing = 0; | ... | ... |