|
@@ -37,6 +37,8 @@
|
|
|
|
|
|
#import "KSNewAlertView.h"
|
|
|
#import "KSLogManager.h"
|
|
|
+#import "KSSourceDownloadAlert.h"
|
|
|
+#import "KSPlatformDownloadAlert.h"
|
|
|
|
|
|
typedef NS_ENUM(NSInteger, CHOOSETYPE) {
|
|
|
CHOOSETYPE_XML,
|
|
@@ -72,12 +74,19 @@ typedef NS_ENUM(NSInteger, CHOOSETYPE) {
|
|
|
|
|
|
@property (nonatomic, strong) KSUMShareManager *shareManager;
|
|
|
|
|
|
-@property (nonatomic, assign) BOOL isDownloadFile;
|
|
|
|
|
|
@property (nonatomic, strong) KSNewAlertView *wifiAlert;
|
|
|
// 是否需要重新加载
|
|
|
@property (nonatomic, assign) BOOL needReload;
|
|
|
|
|
|
+@property (nonatomic, assign) BOOL isDownloadFile;
|
|
|
+
|
|
|
+@property (nonatomic, strong) NSDictionary *downloadParm;
|
|
|
+// 下载文件地址
|
|
|
+@property (nonatomic, strong) NSURL *downloadFileUrl;
|
|
|
+//文件预览(写全局变量,否则操作不成功)
|
|
|
+@property (nonatomic, strong) UIDocumentInteractionController *documentVC;
|
|
|
+
|
|
|
@end
|
|
|
|
|
|
@implementation KSBaseWKWebViewController
|
|
@@ -381,6 +390,10 @@ typedef NS_ENUM(NSInteger, CHOOSETYPE) {
|
|
|
}];
|
|
|
}
|
|
|
}
|
|
|
+ else if ([[parm ks_stringValueForKey:@"api"] isEqualToString:@"downloadFile"]) {
|
|
|
+ NSString *url = [[parm ks_dictionaryValueForKey:@"content"] ks_stringValueForKey:@"downloadUrl"];
|
|
|
+ [self downloadFileWithUrl:url parm:parm];
|
|
|
+ }
|
|
|
// 回调是否刘海屏
|
|
|
else if ([[parm ks_stringValueForKey:@"api"] isEqualToString:@"isSpecialShapedScreen"]) {
|
|
|
BOOL isShapedScreen = iPhoneXSafeTopMargin > 0 ? YES : NO;
|
|
@@ -712,9 +725,87 @@ typedef NS_ENUM(NSInteger, CHOOSETYPE) {
|
|
|
[sendParm setValue:content forKey:@"content"];
|
|
|
[self postMessage:sendParm];
|
|
|
}
|
|
|
+}
|
|
|
+
|
|
|
+- (void)downloadFileWithUrl:(NSString *)fileUrl parm:(NSDictionary *)parm {
|
|
|
+ [LOADING_MANAGER showCustomLoading:@"文件下载中"];
|
|
|
+ [KSNetworkingManager downloadFileRequestWithFileUrl:fileUrl progress:^(int64_t bytesRead, int64_t totalBytes) {
|
|
|
+ // 显示进度
|
|
|
+ NSInteger progress = (NSInteger)(bytesRead*1.0 / totalBytes) * 100;
|
|
|
+ NSString *tipsString = [NSString stringWithFormat:@"文件下载中\n%zd%%",progress];
|
|
|
+ dispatch_main_async_safe(^{
|
|
|
+ [LOADING_MANAGER showCustomLoading:tipsString];
|
|
|
+ });
|
|
|
+ } success:^(NSURL * _Nonnull fileUrl) {
|
|
|
+ [LOADING_MANAGER removeCustomLoading];
|
|
|
+ // 修改文件名
|
|
|
+ NSURL *saveUrl = fileUrl;
|
|
|
+ NSDictionary *content = [parm ks_dictionaryValueForKey:@"content"];
|
|
|
+ NSString *fileName = [content ks_stringValueForKey:@"fileName"];
|
|
|
+ if (![NSString isEmptyString:fileName]) { // 重命名
|
|
|
+ saveUrl = [self renameFile:fileUrl withNewName:fileName];
|
|
|
+ }
|
|
|
+ [self saveFileWithPath:saveUrl sendParm:parm];
|
|
|
+ } faliure:^(NSError * _Nonnull error) {
|
|
|
+ [LOADING_MANAGER removeCustomLoading];
|
|
|
+ [self downloadCallback:NO withParm:parm];
|
|
|
+ }];
|
|
|
+}
|
|
|
+
|
|
|
+- (void)downloadCallback:(BOOL)isSuccess withParm:(NSDictionary *)parm {
|
|
|
+ NSMutableDictionary *sendParm = [NSMutableDictionary dictionaryWithDictionary:parm];
|
|
|
+ NSMutableDictionary *content = [NSMutableDictionary dictionaryWithDictionary:[parm ks_dictionaryValueForKey:@"content"]];
|
|
|
+ [content setValue:@(isSuccess) forKey:@"isSuccess"];
|
|
|
+ [sendParm setValue:content forKey:@"content"];
|
|
|
+ [self postMessage:sendParm];
|
|
|
+}
|
|
|
+
|
|
|
+- (NSURL *)renameFile:(NSURL *)fileUrl withNewName:(NSString *)fileName {
|
|
|
+ // 获取文件的路径
|
|
|
+ NSURL *directoryURL = [fileUrl URLByDeletingLastPathComponent];
|
|
|
+ // 旧文件名
|
|
|
+ NSString *oldFileName = [fileUrl lastPathComponent];
|
|
|
+ NSString *fileExtension = [oldFileName pathExtension];
|
|
|
+ // 当前时间戳
|
|
|
+ NSTimeInterval interval = [[NSDate date] timeIntervalSince1970] *1000;
|
|
|
+ // 构建新的文件名
|
|
|
+ NSString *newFileName = [NSString stringWithFormat:@"%.0f_%@.%@", interval, fileName, fileExtension];
|
|
|
+ // 构建新文件的完整 URL
|
|
|
+ NSURL *newURL = [directoryURL URLByAppendingPathComponent:newFileName];
|
|
|
+
|
|
|
+ // 使用 NSFileManager 移动文件以重命名
|
|
|
+ NSFileManager *fileManager = [NSFileManager defaultManager];
|
|
|
+
|
|
|
+ // 如果存在newURL 移除
|
|
|
+ if ([fileManager fileExistsAtPath:[newURL path]]) {
|
|
|
+ [fileManager removeItemAtURL:newURL error:nil];
|
|
|
+ }
|
|
|
|
|
|
+ NSError *error = nil;
|
|
|
+ BOOL success = [fileManager moveItemAtURL:fileUrl toURL:newURL error:&error];
|
|
|
+ if (success) {
|
|
|
+ return newURL;
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ return fileUrl;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+- (void)saveFileWithPath:(NSURL *)fileUrl sendParm:(NSDictionary *)parm {
|
|
|
+ self.downloadParm = parm;
|
|
|
+ self.isDownloadFile = YES;
|
|
|
+ self.downloadFileUrl = fileUrl;
|
|
|
+ // 保存到文件目录下
|
|
|
+ KSDocumentViewController *documentPickerVC = [[KSDocumentViewController alloc] initWithURL:fileUrl inMode:UIDocumentPickerModeExportToService];
|
|
|
+ documentPickerVC.buttonColor = THEMECOLOR;
|
|
|
+ // 设置代理
|
|
|
+ documentPickerVC.delegate = self;
|
|
|
+ // 设置模态弹出方式
|
|
|
+ documentPickerVC.modalPresentationStyle = UIModalPresentationFormSheet;
|
|
|
+ [self.navigationController presentViewController:documentPickerVC animated:YES completion:nil];
|
|
|
}
|
|
|
|
|
|
+
|
|
|
- (void)afterCheckCameraCheckMic:(PREMISSIONTYPE)cameraType parm:(NSDictionary *)sourceParm {
|
|
|
|
|
|
[RecordCheckManager checkMicPermissionAvaiableCallback:^(PREMISSIONTYPE type) {
|
|
@@ -842,8 +933,9 @@ typedef NS_ENUM(NSInteger, CHOOSETYPE) {
|
|
|
|
|
|
- (void)saveFileToPhone:(NSURL *)fileUrl {
|
|
|
self.isDownloadFile = YES;
|
|
|
-
|
|
|
- UIDocumentPickerViewController *documentPicker = [[UIDocumentPickerViewController alloc] initWithURL:fileUrl inMode:UIDocumentPickerModeExportToService];
|
|
|
+ self.downloadFileUrl = fileUrl;
|
|
|
+ KSDocumentViewController *documentPicker = [[KSDocumentViewController alloc] initWithURL:fileUrl inMode:UIDocumentPickerModeExportToService];
|
|
|
+ documentPicker.buttonColor = THEMECOLOR;
|
|
|
documentPicker.delegate = self;
|
|
|
documentPicker.modalPresentationStyle = UIModalPresentationFormSheet;
|
|
|
[self presentViewController:documentPicker animated:YES completion:nil];
|
|
@@ -878,6 +970,7 @@ typedef NS_ENUM(NSInteger, CHOOSETYPE) {
|
|
|
self.fileChooseType = fileTyle;
|
|
|
NSArray *documentTypes = @[@"public.content", @"public.text", @"public.source-code", @"public.image", @"public.audio", @"public.audiovisual-content", @"com.adobe.pdf", @"com.apple.keynote.key", @"com.microsoft.word.doc", @"com.microsoft.excel.xls", @"com.microsoft.powerpoint.ppt"];
|
|
|
KSDocumentViewController *documentPickerViewController = [[KSDocumentViewController alloc] initWithDocumentTypes:documentTypes inMode:UIDocumentPickerModeImport];
|
|
|
+ documentPickerViewController.buttonColor = THEMECOLOR;
|
|
|
documentPickerViewController.delegate = self;
|
|
|
documentPickerViewController.modalPresentationStyle = UIModalPresentationFullScreen;
|
|
|
[self presentViewController:documentPickerViewController animated:YES completion:nil];
|
|
@@ -1579,78 +1672,51 @@ typedef NS_ENUM(NSInteger, CHOOSETYPE) {
|
|
|
- (void)documentPickerWasCancelled:(UIDocumentPickerViewController *)controller {
|
|
|
if (self.isDownloadFile) {
|
|
|
self.isDownloadFile = NO;
|
|
|
+ if (self.downloadParm) {
|
|
|
+ [self downloadCallback:NO withParm:self.downloadParm];
|
|
|
+ self.downloadParm = nil;
|
|
|
+ }
|
|
|
}
|
|
|
else {
|
|
|
[self fileChooseErrorCallback];
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-- (void)fileChooseErrorCallback {
|
|
|
- if (self.chooseFileParm) { // 回调
|
|
|
- [self.chooseFileParm setValue:@"" forKey:@"fileUrl"];
|
|
|
- [self postMessage:self.chooseFileParm];
|
|
|
- self.chooseFileParm = nil;
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-- (void)uploadFile:(NSString *)fileName fileUrl:(NSString *)fileUrl {
|
|
|
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
|
|
- [LOADING_MANAGER showHUD];
|
|
|
- NSString *suffix = [NSString stringWithFormat:@".%@",[[fileName componentsSeparatedByString:@"."] lastObject]];
|
|
|
- NSData *fileData = [NSData dataWithContentsOfURL:[NSURL fileURLWithPath:fileUrl]];
|
|
|
- [UPLOAD_MANAGER configWithfilePath:@"/user/"];
|
|
|
- [UPLOAD_MANAGER uploadFile:fileData fileName:@"file" fileSuffix:suffix progress:^(int64_t bytesWritten, int64_t totalBytes) {
|
|
|
- int progress = (int)(bytesWritten / totalBytes * 100);
|
|
|
- __block NSString *tipsMessage = [NSString stringWithFormat:@"上传中 %d%%",progress];
|
|
|
- dispatch_main_async_safe(^{
|
|
|
- [LOADING_MANAGER.loadingView setDisplayText:tipsMessage];
|
|
|
- });
|
|
|
- } successCallback:^(NSMutableArray * _Nonnull fileUrlArray) {
|
|
|
- [LOADING_MANAGER removeHUD];
|
|
|
- NSString *fileUrl = [fileUrlArray lastObject];
|
|
|
- if (self.chooseFileParm) { // 回调
|
|
|
- [self.chooseFileParm setValue:fileUrl forKey:@"fileUrl"];
|
|
|
- [self postMessage:self.chooseFileParm];
|
|
|
- self.chooseFileParm = nil;
|
|
|
- }
|
|
|
- } faliure:^(NSError * _Nullable error, NSString * _Nullable descMessaeg) {
|
|
|
- [LOADING_MANAGER removeHUD];
|
|
|
- [LOADING_MANAGER MBShowAUTOHidingInWindow:descMessaeg];
|
|
|
- [self fileChooseErrorCallback];
|
|
|
- }];
|
|
|
- });
|
|
|
-}
|
|
|
-
|
|
|
-- (CGFloat)getFileSize:(NSURL *)fileUrl {
|
|
|
- NSFileManager *fileManager = [NSFileManager defaultManager];
|
|
|
- float filesize = -1.0;
|
|
|
- NSString *path = fileUrl.path;
|
|
|
- if ([fileManager fileExistsAtPath:path]) {
|
|
|
- NSDictionary *fileDic = [fileManager attributesOfItemAtPath:path error:nil];//获取文件的属性
|
|
|
- unsigned long long size = [[fileDic objectForKey:NSFileSize] longLongValue];
|
|
|
- filesize = 1.0*size/1024/1024;
|
|
|
- }
|
|
|
- return filesize;
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-#pragma mark - UIDocumentInteractionControllerDelegate
|
|
|
--(UIViewController*)documentInteractionControllerViewControllerForPreview:(UIDocumentInteractionController*)controller{
|
|
|
- return self;
|
|
|
-}
|
|
|
--(UIView*)documentInteractionControllerViewForPreview:(UIDocumentInteractionController*)controller {
|
|
|
- return self.view;
|
|
|
-}
|
|
|
--(CGRect)documentInteractionControllerRectForPreview:(UIDocumentInteractionController*)controller {
|
|
|
- return self.view.frame;
|
|
|
-}
|
|
|
-#pragma mark - UIDocumentPickerDelegate
|
|
|
- (void)documentPicker:(UIDocumentPickerViewController *)controller didPickDocumentsAtURLs:(NSArray <NSURL *>*)urls {
|
|
|
if (self.isDownloadFile) {
|
|
|
self.isDownloadFile = NO;
|
|
|
- //保存成功
|
|
|
- [LOADING_MANAGER MBShowAUTOHidingInWindow:@"保存成功"];
|
|
|
+ [self downloadCallback:YES withParm:self.downloadParm];
|
|
|
+ self.downloadParm = nil;
|
|
|
+
|
|
|
+ NSURL *descUrl = [urls firstObject];
|
|
|
+ NSString *desc = [descUrl absoluteString];
|
|
|
+
|
|
|
+ if ([UserDefaultObjectForKey(TENANT_ID) integerValue] > 0) { // 机构
|
|
|
+ KSSourceDownloadAlert *alertView = [KSSourceDownloadAlert shareInstance];
|
|
|
+ [alertView configWithDesc:desc];
|
|
|
+ [alertView actionCallbackCancel:^{
|
|
|
+
|
|
|
+ } copyCallback:^{
|
|
|
+ [self copyAction:desc];
|
|
|
+ } sure:^{
|
|
|
+ [self openFileSource:descUrl];
|
|
|
+ }];
|
|
|
+ [alertView showAlert];
|
|
|
+ }
|
|
|
+ else {
|
|
|
+
|
|
|
+ KSPlatformDownloadAlert *alertView = [KSPlatformDownloadAlert shareInstance];
|
|
|
+ [alertView configWithDesc:desc];
|
|
|
+ [alertView actionCallbackCancel:^{
|
|
|
+
|
|
|
+ } copyCallback:^{
|
|
|
+ [self copyAction:desc];
|
|
|
+ } sure:^{
|
|
|
+ [self openFileSource:descUrl];
|
|
|
+ }];
|
|
|
+ [alertView showAlert];
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
else {
|
|
|
NSURL *url = [urls lastObject];
|
|
@@ -1720,6 +1786,110 @@ typedef NS_ENUM(NSInteger, CHOOSETYPE) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+- (void)openFileSource:(NSURL *)path {
|
|
|
+ if (self.downloadFileUrl) {
|
|
|
+ [self displayFileWithUrl:path];
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ // 开始访问权限
|
|
|
+ BOOL fileUrlAuthozied = [path startAccessingSecurityScopedResource];
|
|
|
+
|
|
|
+ if (fileUrlAuthozied) {
|
|
|
+ // 通过 NSFileCoordinator 来协调读取
|
|
|
+ NSFileCoordinator *fileCoordinator = [[NSFileCoordinator alloc] init];
|
|
|
+ NSError *error = nil;
|
|
|
+
|
|
|
+ [fileCoordinator coordinateReadingItemAtURL:path options:0 error:&error byAccessor:^(NSURL *newURL) {
|
|
|
+ // 打开文档
|
|
|
+ [self displayFileWithUrl:newURL];
|
|
|
+ }];
|
|
|
+ // 释放权限
|
|
|
+ [path stopAccessingSecurityScopedResource];
|
|
|
+ } else {
|
|
|
+ [LOADING_MANAGER MBShowAUTOHidingInWindow:@"无法访问文件"];
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+- (void)displayFileWithUrl:(NSURL *)url {
|
|
|
+ // 打开文档
|
|
|
+ self.documentVC = [UIDocumentInteractionController interactionControllerWithURL:url];
|
|
|
+ // 2. 设置代理(如果需要处理特定交互事件)
|
|
|
+ self.documentVC.delegate = self;
|
|
|
+
|
|
|
+ // 3. 显示“打开方式”菜单或文件预览
|
|
|
+ // 从指定的视图呈现操作菜单
|
|
|
+ [self.documentVC presentOptionsMenuFromRect:self.view.bounds inView:self.view animated:YES];
|
|
|
+}
|
|
|
+
|
|
|
+- (void)copyAction:(NSString *)desc {
|
|
|
+ // 复制
|
|
|
+ UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
|
|
|
+ pasteboard.string = [NSString returnNoNullStringWithString:desc];
|
|
|
+ [LOADING_MANAGER MBShowAUTOHidingInWindow:@"复制成功"];
|
|
|
+}
|
|
|
+
|
|
|
+- (void)fileChooseErrorCallback {
|
|
|
+ if (self.chooseFileParm) { // 回调
|
|
|
+ [self.chooseFileParm setValue:@"" forKey:@"fileUrl"];
|
|
|
+ [self postMessage:self.chooseFileParm];
|
|
|
+ self.chooseFileParm = nil;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+- (void)uploadFile:(NSString *)fileName fileUrl:(NSString *)fileUrl {
|
|
|
+ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
|
|
+ [LOADING_MANAGER showHUD];
|
|
|
+ NSString *suffix = [NSString stringWithFormat:@".%@",[[fileName componentsSeparatedByString:@"."] lastObject]];
|
|
|
+ NSData *fileData = [NSData dataWithContentsOfURL:[NSURL fileURLWithPath:fileUrl]];
|
|
|
+ [UPLOAD_MANAGER configWithfilePath:@"/user/"];
|
|
|
+ [UPLOAD_MANAGER uploadFile:fileData fileName:@"file" fileSuffix:suffix progress:^(int64_t bytesWritten, int64_t totalBytes) {
|
|
|
+ int progress = (int)(bytesWritten / totalBytes * 100);
|
|
|
+ __block NSString *tipsMessage = [NSString stringWithFormat:@"上传中 %d%%",progress];
|
|
|
+ dispatch_main_async_safe(^{
|
|
|
+ [LOADING_MANAGER.loadingView setDisplayText:tipsMessage];
|
|
|
+ });
|
|
|
+ } successCallback:^(NSMutableArray * _Nonnull fileUrlArray) {
|
|
|
+ [LOADING_MANAGER removeHUD];
|
|
|
+ NSString *fileUrl = [fileUrlArray lastObject];
|
|
|
+ if (self.chooseFileParm) { // 回调
|
|
|
+ [self.chooseFileParm setValue:fileUrl forKey:@"fileUrl"];
|
|
|
+ [self postMessage:self.chooseFileParm];
|
|
|
+ self.chooseFileParm = nil;
|
|
|
+ }
|
|
|
+ } faliure:^(NSError * _Nullable error, NSString * _Nullable descMessaeg) {
|
|
|
+ [LOADING_MANAGER removeHUD];
|
|
|
+ [LOADING_MANAGER MBShowAUTOHidingInWindow:descMessaeg];
|
|
|
+ [self fileChooseErrorCallback];
|
|
|
+ }];
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
+- (CGFloat)getFileSize:(NSURL *)fileUrl {
|
|
|
+ NSFileManager *fileManager = [NSFileManager defaultManager];
|
|
|
+ float filesize = -1.0;
|
|
|
+ NSString *path = fileUrl.path;
|
|
|
+ if ([fileManager fileExistsAtPath:path]) {
|
|
|
+ NSDictionary *fileDic = [fileManager attributesOfItemAtPath:path error:nil];//获取文件的属性
|
|
|
+ unsigned long long size = [[fileDic objectForKey:NSFileSize] longLongValue];
|
|
|
+ filesize = 1.0*size/1024/1024;
|
|
|
+ }
|
|
|
+ return filesize;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+#pragma mark - UIDocumentInteractionControllerDelegate
|
|
|
+-(UIViewController*)documentInteractionControllerViewControllerForPreview:(UIDocumentInteractionController*)controller{
|
|
|
+ return self;
|
|
|
+}
|
|
|
+-(UIView*)documentInteractionControllerViewForPreview:(UIDocumentInteractionController*)controller {
|
|
|
+ return self.view;
|
|
|
+}
|
|
|
+-(CGRect)documentInteractionControllerRectForPreview:(UIDocumentInteractionController*)controller {
|
|
|
+ return self.view.frame;
|
|
|
+}
|
|
|
+
|
|
|
#pragma mark ---- 镜像和投屏检测
|
|
|
|
|
|
- (void)captureViewTips:(NSNotification *)notification {
|