|
@@ -10,6 +10,7 @@
|
|
|
#import <WebKit/WebKit.h>
|
|
|
#import "SafeForKey.h"
|
|
|
#import "iPhone.h"
|
|
|
+#import "fileUploadToFileCenterModel.h"
|
|
|
|
|
|
@interface CustomerWebViewController ()<WKScriptMessageHandler,WKNavigationDelegate,WKUIDelegate>
|
|
|
|
|
@@ -24,12 +25,14 @@
|
|
|
-(void)viewWillAppear:(BOOL)animated {
|
|
|
[super viewWillAppear:animated];
|
|
|
[self.webView.configuration.userContentController addScriptMessageHandler:self name:@"share"];
|
|
|
+ [self.webView.configuration.userContentController addScriptMessageHandler:self name:@"getFileKey"];
|
|
|
}
|
|
|
|
|
|
- (void)viewWillDisappear:(BOOL)animated {
|
|
|
[super viewWillDisappear:animated];
|
|
|
|
|
|
[self.webView.configuration.userContentController removeScriptMessageHandlerForName:@"share"];
|
|
|
+ [self.webView.configuration.userContentController removeScriptMessageHandlerForName:@"getFileKey"];
|
|
|
}
|
|
|
|
|
|
- (void)viewDidAppear:(BOOL)animated {
|
|
@@ -175,8 +178,8 @@
|
|
|
//这句是必须加上的,不然会异常
|
|
|
decisionHandler(actionPolicy);
|
|
|
|
|
|
- NSArray *arrViewControllers = self.navigationController.viewControllers;
|
|
|
- NSInteger index = [arrViewControllers indexOfObject:self];
|
|
|
+// NSArray *arrViewControllers = self.navigationController.viewControllers;
|
|
|
+// NSInteger index = [arrViewControllers indexOfObject:self];
|
|
|
}
|
|
|
|
|
|
// 在发送请求之前,决定是否跳转
|
|
@@ -196,9 +199,78 @@
|
|
|
- (void)userContentController:(WKUserContentController *)userContentController didReceiveScriptMessage:(WKScriptMessage *)message {
|
|
|
HLog(@"%@",message.body);
|
|
|
HLog(@"%@",message.name);
|
|
|
- [[iToast makeText:@"已接收到消息"] show];
|
|
|
+ //[[iToast makeText:@"已接收到消息"] show];
|
|
|
+
|
|
|
+
|
|
|
+ if([message.name isEqualToString:@"getFileKey"])
|
|
|
+ {//帮助反馈 h5调用原生 需要日志的FileKey
|
|
|
+ [self gotoAddLogFun];
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
|
|
|
+#pragma mark 获取瑞云日志上传到文件中心
|
|
|
+
|
|
|
+//1.读取日志
|
|
|
+//2.上传到文件中心
|
|
|
+//3.拿到key上传到盒子服务器
|
|
|
+- (void)gotoAddLogFun
|
|
|
+{
|
|
|
+
|
|
|
+ //1.读取日志
|
|
|
+ NSString *ruiyunLogPath = [NSString stringWithFormat:@"%@/logs/debug_0.log",CachesPatch];
|
|
|
+ NSData *logData = [NSData dataWithContentsOfFile:ruiyunLogPath];
|
|
|
+ HLog(@"%@",logData);
|
|
|
+
|
|
|
+ if(!logData || [logData length]==0){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ //2.上传到文件中心
|
|
|
+ NSMutableDictionary *paraDict = [NSMutableDictionary new];
|
|
|
+
|
|
|
+ NSString *snStr = [connectDeviceManager shareInstance].DeviceThirdIdMod.data.changeSn;
|
|
|
+ if(!snStr){
|
|
|
+ snStr = [iTools getNowTimeString];
|
|
|
+ }
|
|
|
+ NSString*filename = [[NSString alloc] initWithFormat:@"%@_ios.log",snStr];
|
|
|
+
|
|
|
+ [paraDict setValue:filename forKey:@"filename"];
|
|
|
+
|
|
|
+ KWeakSelf
|
|
|
+ [[netWorkManager shareInstance] doUploadFileToFileServiceWithParams:paraDict data:logData success:^(id _Nonnull responseObject) {
|
|
|
+ HLog(@"%@",responseObject);
|
|
|
+
|
|
|
+ fileUploadToFileCenterModel *model = [[fileUploadToFileCenterModel alloc] initWithDictionary:responseObject error:nil];
|
|
|
+ if(model.code == 200){
|
|
|
+ NSString * fileKey = model.data.fileKey;
|
|
|
+ if(fileKey && fileKey.length >0){
|
|
|
+ [weakSelf getFileKeyToH5By:fileKey];
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ [weakSelf getFileKeyToH5By:@""];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ [weakSelf getFileKeyToH5By:@""];
|
|
|
+ }
|
|
|
+
|
|
|
+ } faild:^(NSError * _Nonnull error) {
|
|
|
+ [weakSelf getFileKeyToH5By:@""];
|
|
|
+ }];
|
|
|
+}
|
|
|
+
|
|
|
+#pragma mark 拿到文件中心的key给h5
|
|
|
+- (void)getFileKeyToH5By:(NSString*)fileKey
|
|
|
+{
|
|
|
+ NSString *jsFunction = @"transferFileKey('%@');";
|
|
|
+ jsFunction = [jsFunction stringByReplacingOccurrencesOfString:@"%@" withString:fileKey];
|
|
|
+ [self.webView evaluateJavaScript:jsFunction completionHandler:^(id _Nullable result, NSError * _Nullable error) {
|
|
|
+ if (error != nil) {
|
|
|
+ NSLog(@"Error evaluating JavaScript: %@", error);
|
|
|
+ }
|
|
|
+ }];
|
|
|
+
|
|
|
+}
|
|
|
|
|
|
@end
|