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,7 +38,7 @@ TODO: Add long description of the pod here. | ||
| 38 | 38 | ||
| 39 | s.public_header_files = 'CNLiveUserAgreementManager/Classes/**/*.h' | 39 | s.public_header_files = 'CNLiveUserAgreementManager/Classes/**/*.h' |
| 40 | # s.frameworks = 'UIKit', 'MapKit' | 40 | # s.frameworks = 'UIKit', 'MapKit' |
| 41 | - # | 41 | + s.dependency 'QMUIKit' |
| 42 | s.dependency 'WebViewJavascriptBridge' | 42 | s.dependency 'WebViewJavascriptBridge' |
| 43 | s.dependency 'CNLiveRequestBastKit' | 43 | s.dependency 'CNLiveRequestBastKit' |
| 44 | s.dependency 'CNLiveEnvironment' | 44 | s.dependency 'CNLiveEnvironment' |
CNLiveUserAgreementManager/Classes/CNLiveAgreementWebController.m
| @@ -12,6 +12,8 @@ | @@ -12,6 +12,8 @@ | ||
| 12 | #import <WebKit/WebKit.h> | 12 | #import <WebKit/WebKit.h> |
| 13 | // 环境库 | 13 | // 环境库 |
| 14 | #import "CNLiveEnvironment.h" | 14 | #import "CNLiveEnvironment.h" |
| 15 | +#import "QMUIKit.h" | ||
| 16 | +#import <CNLiveRequestBastKit/CNLiveNetworking.h> | ||
| 15 | 17 | ||
| 16 | @interface CNLiveAgreementWebController ()<WKUIDelegate, WKNavigationDelegate> | 18 | @interface CNLiveAgreementWebController ()<WKUIDelegate, WKNavigationDelegate> |
| 17 | @property (nonatomic, copy) NSString *url; | 19 | @property (nonatomic, copy) NSString *url; |
| @@ -23,6 +25,8 @@ | @@ -23,6 +25,8 @@ | ||
| 23 | @property (nonatomic, strong) UIProgressView *processView; | 25 | @property (nonatomic, strong) UIProgressView *processView; |
| 24 | @property (nonatomic, weak) UILabel *titleLabel; | 26 | @property (nonatomic, weak) UILabel *titleLabel; |
| 25 | 27 | ||
| 28 | +@property (nonatomic, strong) NSMutableArray *photos;// 上传图片 | ||
| 29 | + | ||
| 26 | @end | 30 | @end |
| 27 | 31 | ||
| 28 | @implementation CNLiveAgreementWebController | 32 | @implementation CNLiveAgreementWebController |
| @@ -78,12 +82,13 @@ | @@ -78,12 +82,13 @@ | ||
| 78 | [self interaction]; | 82 | [self interaction]; |
| 79 | [self loadUrl]; | 83 | [self loadUrl]; |
| 80 | 84 | ||
| 85 | + [self getImageToken]; | ||
| 86 | + | ||
| 81 | } | 87 | } |
| 82 | 88 | ||
| 83 | - (void)dealloc { | 89 | - (void)dealloc { |
| 84 | if(TestEnvironment){ | 90 | if(TestEnvironment){ |
| 85 | NSLog(@"CNUserAgreementWebController dealloc"); | 91 | NSLog(@"CNUserAgreementWebController dealloc"); |
| 86 | - | ||
| 87 | } | 92 | } |
| 88 | [self.webView stopLoading]; | 93 | [self.webView stopLoading]; |
| 89 | [self.webView removeObserver:self forKeyPath:@"estimatedProgress"]; | 94 | [self.webView removeObserver:self forKeyPath:@"estimatedProgress"]; |
| @@ -124,7 +129,10 @@ | @@ -124,7 +129,10 @@ | ||
| 124 | } | 129 | } |
| 125 | __strong typeof(weakSelf) strongSelf = weakSelf; | 130 | __strong typeof(weakSelf) strongSelf = weakSelf; |
| 126 | if(strongSelf){ | 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 | responseCallback(data); | 137 | responseCallback(data); |
| 130 | }]; | 138 | }]; |
| @@ -136,6 +144,19 @@ | @@ -136,6 +144,19 @@ | ||
| 136 | } | 144 | } |
| 137 | __strong typeof(weakSelf) strongSelf = weakSelf; | 145 | __strong typeof(weakSelf) strongSelf = weakSelf; |
| 138 | if(strongSelf){ | 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 | responseCallback(data); | 162 | responseCallback(data); |
| @@ -148,7 +169,8 @@ | @@ -148,7 +169,8 @@ | ||
| 148 | } | 169 | } |
| 149 | __strong typeof(weakSelf) strongSelf = weakSelf; | 170 | __strong typeof(weakSelf) strongSelf = weakSelf; |
| 150 | if(strongSelf){ | 171 | if(strongSelf){ |
| 151 | - | 172 | + [QMUITips hideAllToastInView:strongSelf.view animated:YES]; |
| 173 | + | ||
| 152 | } | 174 | } |
| 153 | responseCallback(data); | 175 | responseCallback(data); |
| 154 | }]; | 176 | }]; |
| @@ -184,7 +206,12 @@ | @@ -184,7 +206,12 @@ | ||
| 184 | } | 206 | } |
| 185 | __strong typeof(weakSelf) strongSelf = weakSelf; | 207 | __strong typeof(weakSelf) strongSelf = weakSelf; |
| 186 | if(strongSelf){ | 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 | responseCallback(data); | 216 | responseCallback(data); |
| 190 | }]; | 217 | }]; |
| @@ -381,6 +408,13 @@ | @@ -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 | #pragma mark - 私有方法 | 419 | #pragma mark - 私有方法 |
| 386 | // 清除缓存 | 420 | // 清除缓存 |
| @@ -413,4 +447,44 @@ | @@ -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 | @end | 490 | @end |
Example/CNLiveUserAgreementManager.xcodeproj/project.pbxproj
| @@ -310,6 +310,7 @@ | @@ -310,6 +310,7 @@ | ||
| 310 | "${BUILT_PRODUCTS_DIR}/CNLiveEnvironment/CNLiveEnvironment.framework", | 310 | "${BUILT_PRODUCTS_DIR}/CNLiveEnvironment/CNLiveEnvironment.framework", |
| 311 | "${BUILT_PRODUCTS_DIR}/CNLiveRequestBastKit/CNLiveRequestBastKit.framework", | 311 | "${BUILT_PRODUCTS_DIR}/CNLiveRequestBastKit/CNLiveRequestBastKit.framework", |
| 312 | "${BUILT_PRODUCTS_DIR}/CNLiveUserAgreementManager/CNLiveUserAgreementManager.framework", | 312 | "${BUILT_PRODUCTS_DIR}/CNLiveUserAgreementManager/CNLiveUserAgreementManager.framework", |
| 313 | + "${BUILT_PRODUCTS_DIR}/QMUIKit/QMUIKit.framework", | ||
| 313 | "${BUILT_PRODUCTS_DIR}/WebViewJavascriptBridge/WebViewJavascriptBridge.framework", | 314 | "${BUILT_PRODUCTS_DIR}/WebViewJavascriptBridge/WebViewJavascriptBridge.framework", |
| 314 | ); | 315 | ); |
| 315 | name = "[CP] Embed Pods Frameworks"; | 316 | name = "[CP] Embed Pods Frameworks"; |
| @@ -320,6 +321,7 @@ | @@ -320,6 +321,7 @@ | ||
| 320 | "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/CNLiveEnvironment.framework", | 321 | "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/CNLiveEnvironment.framework", |
| 321 | "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/CNLiveRequestBastKit.framework", | 322 | "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/CNLiveRequestBastKit.framework", |
| 322 | "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/CNLiveUserAgreementManager.framework", | 323 | "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/CNLiveUserAgreementManager.framework", |
| 324 | + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/QMUIKit.framework", | ||
| 323 | "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/WebViewJavascriptBridge.framework", | 325 | "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/WebViewJavascriptBridge.framework", |
| 324 | ); | 326 | ); |
| 325 | runOnlyForDeploymentPostprocessing = 0; | 327 | runOnlyForDeploymentPostprocessing = 0; |