Browse Source

文件上传

Steven 3 years ago
parent
commit
099df146c4

+ 30 - 0
KulexiuForTeacher/KulexiuForTeacher.xcodeproj/project.pbxproj

@@ -451,6 +451,9 @@
 		BCB6340627F6A2F000ACFDCF /* tick.wav in Resources */ = {isa = PBXBuildFile; fileRef = BCB6340427F6A2F000ACFDCF /* tick.wav */; };
 		BCB6340927F6A35700ACFDCF /* LiveroomTimeManager.m in Sources */ = {isa = PBXBuildFile; fileRef = BCB6340827F6A35700ACFDCF /* LiveroomTimeManager.m */; };
 		BCB635B627F6FB0A00ACFDCF /* SeatTipsView.m in Sources */ = {isa = PBXBuildFile; fileRef = BCB635B527F6FB0A00ACFDCF /* SeatTipsView.m */; };
+		BCB635B927F722E800ACFDCF /* KSDocumentViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = BCB635B827F722E800ACFDCF /* KSDocumentViewController.m */; };
+		BCB635BE27F7256B00ACFDCF /* KSICloudManager.m in Sources */ = {isa = PBXBuildFile; fileRef = BCB635BA27F7256B00ACFDCF /* KSICloudManager.m */; };
+		BCB635BF27F7256B00ACFDCF /* KSDocument.m in Sources */ = {isa = PBXBuildFile; fileRef = BCB635BD27F7256B00ACFDCF /* KSDocument.m */; };
 		BCC9F35527F5F4FD00647449 /* LiveSeatMember.m in Sources */ = {isa = PBXBuildFile; fileRef = BCC9F35427F5F4FD00647449 /* LiveSeatMember.m */; };
 		BCC9F40727F69BD200647449 /* SealClass.strings in Resources */ = {isa = PBXBuildFile; fileRef = BCC9F35C27F69BD100647449 /* SealClass.strings */; };
 		BCC9F40927F69BD200647449 /* ZoomControl.m in Sources */ = {isa = PBXBuildFile; fileRef = BCC9F36427F69BD100647449 /* ZoomControl.m */; };
@@ -1362,6 +1365,12 @@
 		BCB6340827F6A35700ACFDCF /* LiveroomTimeManager.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = LiveroomTimeManager.m; sourceTree = "<group>"; };
 		BCB635B427F6FB0A00ACFDCF /* SeatTipsView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SeatTipsView.h; sourceTree = "<group>"; };
 		BCB635B527F6FB0A00ACFDCF /* SeatTipsView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SeatTipsView.m; sourceTree = "<group>"; };
+		BCB635B727F722E800ACFDCF /* KSDocumentViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KSDocumentViewController.h; sourceTree = "<group>"; };
+		BCB635B827F722E800ACFDCF /* KSDocumentViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KSDocumentViewController.m; sourceTree = "<group>"; };
+		BCB635BA27F7256B00ACFDCF /* KSICloudManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KSICloudManager.m; sourceTree = "<group>"; };
+		BCB635BB27F7256B00ACFDCF /* KSICloudManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KSICloudManager.h; sourceTree = "<group>"; };
+		BCB635BC27F7256B00ACFDCF /* KSDocument.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KSDocument.h; sourceTree = "<group>"; };
+		BCB635BD27F7256B00ACFDCF /* KSDocument.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KSDocument.m; sourceTree = "<group>"; };
 		BCC9F35327F5F4FD00647449 /* LiveSeatMember.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = LiveSeatMember.h; sourceTree = "<group>"; };
 		BCC9F35427F5F4FD00647449 /* LiveSeatMember.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = LiveSeatMember.m; sourceTree = "<group>"; };
 		BCC9F35B27F69BD100647449 /* KSRemoteUserManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KSRemoteUserManager.h; sourceTree = "<group>"; };
@@ -1837,8 +1846,14 @@
 		2779309627E30F2D0010E277 /* Base */ = {
 			isa = PBXGroup;
 			children = (
+				BCB635BC27F7256B00ACFDCF /* KSDocument.h */,
+				BCB635BD27F7256B00ACFDCF /* KSDocument.m */,
+				BCB635BB27F7256B00ACFDCF /* KSICloudManager.h */,
+				BCB635BA27F7256B00ACFDCF /* KSICloudManager.m */,
 				27F9CAE827EC177E003E0FE4 /* KSJXBodyView.h */,
 				27F9CAE927EC177F003E0FE4 /* KSJXBodyView.m */,
+				BCB635B727F722E800ACFDCF /* KSDocumentViewController.h */,
+				BCB635B827F722E800ACFDCF /* KSDocumentViewController.m */,
 				27BC3B1627F2B0D200D81E30 /* kSJXCollectionView.h */,
 				27BC3B1727F2B0D200D81E30 /* kSJXCollectionView.m */,
 				275FA1A127E7311600CFEA2E /* KSRCIMDataSource.h */,
@@ -4171,6 +4186,7 @@
 				275E8A6927E18F2300DD3F6E /* AppDelegate.m in Sources */,
 				2779361E27E3338E0010E277 /* KSUpdateManager.m in Sources */,
 				BCC9F42827F69BD200647449 /* WhiteUtils.m in Sources */,
+				BCB635BF27F7256B00ACFDCF /* KSDocument.m in Sources */,
 				2779322D27E30FC30010E277 /* ALCalendarDate.m in Sources */,
 				BCB633FD27F6A18200ACFDCF /* ClassroomMainContainer.m in Sources */,
 				2779321E27E30FC30010E277 /* LifeButton.m in Sources */,
@@ -4252,6 +4268,7 @@
 				277932E227E310070010E277 /* TZImageCropManager.m in Sources */,
 				277932B327E30FFE0010E277 /* QWdynamicModel.m in Sources */,
 				2779329627E30FEB0010E277 /* MSSBrowseZoomScrollView.m in Sources */,
+				BCB635B927F722E800ACFDCF /* KSDocumentViewController.m in Sources */,
 				275E3DE727F4677F0010EC30 /* LiveRoomHeadView.m in Sources */,
 				2779320427E30FC30010E277 /* KSHoldButton.m in Sources */,
 				2779320627E30FC30010E277 /* UIView+ValueAdd.m in Sources */,
@@ -4315,6 +4332,7 @@
 				2779322527E30FC30010E277 /* NSString+MD5.m in Sources */,
 				2779320327E30FC30010E277 /* KSChoosePicker.m in Sources */,
 				BCC9F43027F69BD200647449 /* HTTPResult.m in Sources */,
+				BCB635BE27F7256B00ACFDCF /* KSICloudManager.m in Sources */,
 				277931E527E30FC20010E277 /* NSMutableAttributedString+CZHExtention.m in Sources */,
 				27A54CFC27E9BDB3007309A3 /* AboutUsBodyView.m in Sources */,
 				277931CF27E30FC20010E277 /* UIView+XIBView.m in Sources */,
@@ -4585,6 +4603,11 @@
 				GENERATE_INFOPLIST_FILE = YES;
 				INFOPLIST_FILE = KulexiuForTeacher/Info.plist;
 				INFOPLIST_KEY_CFBundleDisplayName = "酷乐秀老师端";
+				INFOPLIST_KEY_NSAppleMusicUsageDescription = "App需要您的同意访问媒体资料库权限,用于播放媒体服务";
+				INFOPLIST_KEY_NSCameraUsageDescription = "APP需要您的同意,访问您的相机,以便您正常使用上传图片、视频课程等服务";
+				INFOPLIST_KEY_NSMicrophoneUsageDescription = "App需要您的同意访问麦克风权限,用于您的语音服务、视频教学";
+				INFOPLIST_KEY_NSPhotoLibraryAddUsageDescription = "App需要您的同意访问您的相册权限,用于您的图片课件上传服务";
+				INFOPLIST_KEY_NSPhotoLibraryUsageDescription = "App需要您的同意访问您的相册权限,用于您的图片课件上传服务";
 				INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
 				INFOPLIST_KEY_UILaunchStoryboardName = LaunchScreen;
 				INFOPLIST_KEY_UIMainStoryboardFile = Main;
@@ -4592,6 +4615,7 @@
 				INFOPLIST_KEY_UISupportedInterfaceOrientations = UIInterfaceOrientationPortrait;
 				INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
 				INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
+				INFOPLIST_KEY_UIUserInterfaceStyle = Light;
 				IPHONEOS_DEPLOYMENT_TARGET = 11.0;
 				LD_RUNPATH_SEARCH_PATHS = (
 					"$(inherited)",
@@ -4620,6 +4644,11 @@
 				GENERATE_INFOPLIST_FILE = YES;
 				INFOPLIST_FILE = KulexiuForTeacher/Info.plist;
 				INFOPLIST_KEY_CFBundleDisplayName = "酷乐秀老师端";
+				INFOPLIST_KEY_NSAppleMusicUsageDescription = "App需要您的同意访问媒体资料库权限,用于播放媒体服务";
+				INFOPLIST_KEY_NSCameraUsageDescription = "APP需要您的同意,访问您的相机,以便您正常使用上传图片、视频课程等服务";
+				INFOPLIST_KEY_NSMicrophoneUsageDescription = "App需要您的同意访问麦克风权限,用于您的语音服务、视频教学";
+				INFOPLIST_KEY_NSPhotoLibraryAddUsageDescription = "App需要您的同意访问您的相册权限,用于您的图片课件上传服务";
+				INFOPLIST_KEY_NSPhotoLibraryUsageDescription = "App需要您的同意访问您的相册权限,用于您的图片课件上传服务";
 				INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
 				INFOPLIST_KEY_UILaunchStoryboardName = LaunchScreen;
 				INFOPLIST_KEY_UIMainStoryboardFile = Main;
@@ -4627,6 +4656,7 @@
 				INFOPLIST_KEY_UISupportedInterfaceOrientations = UIInterfaceOrientationPortrait;
 				INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
 				INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
+				INFOPLIST_KEY_UIUserInterfaceStyle = Light;
 				IPHONEOS_DEPLOYMENT_TARGET = 11.0;
 				LD_RUNPATH_SEARCH_PATHS = (
 					"$(inherited)",

BIN
KulexiuForTeacher/KulexiuForTeacher.xcworkspace/xcuserdata/wangzhi.xcuserdatad/UserInterfaceState.xcuserstate


+ 328 - 20
KulexiuForTeacher/KulexiuForTeacher/Common/Base/KSBaseWKWebViewController.m

@@ -17,10 +17,20 @@
 #import "KSLocalWebViewController.h"
 #import "RCConnectionManager.h"
 #import "KSAccompanyWebViewController.h"
+#import "KSChatConversationViewController.h"
+#import "KSMediaManager.h"
+#import <AVFoundation/AVFoundation.h>
+#import "KSDocumentViewController.h"
+#import "KSICloudManager.h"
 
-//#import "ChatConversationViewController.h"
+typedef NS_ENUM(NSInteger, CHOOSETYPE) {
+    CHOOSETYPE_XML,
+    CHOOSETYPE_MIDI,
+    CHOOSETYPE_MP3,
+    CHOOSETYPE_ALL,
+};
 
-@interface KSBaseWKWebViewController ()
+@interface KSBaseWKWebViewController ()<UIDocumentPickerDelegate>
 
 @property (nonatomic, assign) BOOL isOutLink;  // 外部链接
 
@@ -34,6 +44,15 @@
 
 @property (nonatomic, assign) BOOL landScape;
 
+/// 选择本地文件 parm
+@property (nonatomic, strong) NSMutableDictionary *chooseFileParm;
+
+@property (nonatomic, strong) KSMediaManager *mediaManager;
+
+@property (strong, nonatomic) MBProgressHUD *HUD;
+
+@property (nonatomic, assign) CHOOSETYPE fileChooseType;
+
 @end
 
 @implementation KSBaseWKWebViewController
@@ -258,9 +277,9 @@
         NSDictionary *valueDic = [parm dictionaryValueForKey:@"content"];
         NSString *name = [valueDic stringValueForKey:@"name"];
         NSString *userId = [NSString stringWithFormat:@"%.0f",[valueDic floatValueForKey:@"userId"]];
-//        ChatConversationViewController *conversationVC = [[ChatConversationViewController alloc] initWithConversationType:ConversationType_PRIVATE targetId:[NSString returnNoNullStringWithString:userId]];
-//        conversationVC.title = [NSString returnNoNullStringWithString:name];
-//        [self.navigationController pushViewController:conversationVC animated:YES];
+        KSChatConversationViewController *conversationVC = [[KSChatConversationViewController alloc] initWithConversationType:ConversationType_PRIVATE targetId:[NSString returnNoNullStringWithString:userId]];
+        conversationVC.title = [NSString returnNoNullStringWithString:name];
+        [self.navigationController pushViewController:conversationVC animated:YES];
     }
     else if ([[parm stringValueForKey:@"api"] isEqualToString:@"openWebView"]) { // 打开新页面
         NSDictionary *valueDic = [parm dictionaryValueForKey:@"content"];
@@ -293,16 +312,16 @@
         NSDictionary *valueDic = [parm dictionaryValueForKey:@"content"];
         if ([valueDic stringValueForKey:@"PDF"]) {
             NSString *url = [valueDic stringValueForKey:@"downloadUrl"];
-//            [KSNetworkingManager downloadFileRequestWithFileUrl:url progress:^(int64_t bytesRead, int64_t totalBytes) {
-//
-//            } success:^(NSURL * _Nonnull fileUrl) {
-//                MJWeakSelf;
-//                [self KSShowMsg:@"下载成功" promptCompletion:^{
-//                    [weakSelf displaySource:fileUrl];
-//                }];
-//            } faliure:^(NSError * _Nonnull error) {
-//
-//            }];
+            [KSNetworkingManager downloadFileRequestWithFileUrl:url progress:^(int64_t bytesRead, int64_t totalBytes) {
+
+            } success:^(NSURL * _Nonnull fileUrl) {
+                MJWeakSelf;
+                [self KSShowMsg:@"下载成功" promptCompletion:^{
+                    [weakSelf displaySource:fileUrl];
+                }];
+            } faliure:^(NSError * _Nonnull error) {
+
+            }];
         }
     }
     // 回调是否刘海屏
@@ -397,11 +416,68 @@
             make.top.mas_equalTo(self.view.mas_top).offset(navHeight);
         }];
     }
-//    else if ([[parm stringValueForKey:@"api"] isEqualToString:@"enterLiveRoom"]) { // 进入直播间
-//        NSDictionary *valueDic = [parm dictionaryValueForKey:@"content"];
-//        NSString *roomId = [valueDic stringValueForKey:@"roomId"];
-//        [KSEnterLiveroomManager joinLiveWithRoomId:roomId inController:(CustomNavViewController *)self.navigationController];
-//    }
+    else if ([[parm stringValueForKey:@"api"] isEqualToString:@"chooseFile"]) {
+        NSDictionary *valueDic = [parm dictionaryValueForKey:@"content"];
+        self.chooseFileParm = [NSMutableDictionary dictionaryWithDictionary:valueDic];
+        NSString *typeStr = [valueDic stringValueForKey:@"type"];
+        NSInteger maxCount = [valueDic integerValueForKey:@"max"];
+        [self chooseFileWithType:typeStr maxNumber:maxCount];
+        
+    }
+}
+
+- (void)chooseFileWithType:(NSString *)typeStr maxNumber:(NSInteger)maxCount {
+    if ([typeStr isEqualToString:@"img"]) { // 选择图片上传
+        if (maxCount > 9) {
+            maxCount = 9;
+        }
+        [self chooseMediaWithType:MEDIATYPE_PHOTO maxCount:maxCount];
+    }
+    else if ([typeStr isEqualToString:@"video"]) {
+        [self chooseMediaWithType:MEDIATYPE_VIDEO maxCount:1];
+    }
+    else if ([typeStr isEqualToString:@"file"]) {
+        [self chooseDocumentWithType:CHOOSETYPE_ALL];
+    }
+    else if ([typeStr isEqualToString:@"midi"]) {
+        [self chooseDocumentWithType:CHOOSETYPE_MIDI];
+    }
+    else if ([typeStr isEqualToString:@"mp3"]) {
+        [self chooseDocumentWithType:CHOOSETYPE_MP3];
+    }
+    else if ([typeStr isEqualToString:@"xml"]) {
+        [self chooseDocumentWithType:CHOOSETYPE_XML];
+    }
+}
+
+- (void)chooseDocumentWithType:(CHOOSETYPE)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.delegate = self;
+//    documentPickerViewController.modalPresentationStyle = UIModalPresentationFullScreen;
+    [self presentViewController:documentPickerViewController animated:YES completion:nil];
+}
+
+- (void)chooseMediaWithType:(MEDIATYPE)type maxCount:(NSInteger)maxCount {
+    self.mediaManager = [[KSMediaManager alloc] init];
+    self.mediaManager.mediaType = type;
+    self.mediaManager.maxPhotoNumber = maxCount;
+    self.mediaManager.baseCtrl = self;
+    self.mediaManager.needCropImage = NO;
+    MJWeakSelf;
+    [self.mediaManager noAlertCallback:^(NSString * _Nullable videoUrl, NSMutableArray * _Nullable imageArray, NSMutableArray * _Nullable imageAsset) {
+        
+        if (type == MEDIATYPE_PHOTO) {
+            [self uploadImageArray:imageArray];
+        }
+        else {
+            NSLog(@"%@", videoUrl);
+            // 上传视频
+            [weakSelf uploadVideoWithUrl:videoUrl];
+        }
+     
+    }];
+    [self.mediaManager pushImagePickerController];
 }
 
 - (UIImage *)imageWithBase64String:(NSString *)base64String {
@@ -818,6 +894,238 @@
     return path;
 }
 
+#pragma mark -- 上传图片
+
+- (void)hudTipWillShow:(BOOL)willShow{
+    if (willShow) {
+        [self resignFirstResponder];
+        UIWindow *keyWindow = [UIApplication sharedApplication].keyWindow;
+        if (!_HUD) {
+            _HUD = [MBProgressHUD showHUDAddedTo:keyWindow animated:YES];
+            _HUD.mode = MBProgressHUDModeDeterminateHorizontalBar;
+            _HUD.label.text = @"正在上传视频...";
+            _HUD.contentColor = [UIColor whiteColor];
+            _HUD.bezelView.style = MBProgressHUDBackgroundStyleSolidColor;
+            _HUD.bezelView.backgroundColor = [UIColor colorWithHexString:@"#000000" alpha:0.8];
+            _HUD.removeFromSuperViewOnHide = YES;
+            
+        }else{
+            _HUD.progress = 0;
+            [keyWindow addSubview:_HUD];
+            [_HUD showAnimated:YES];
+        }
+    }else{
+        [_HUD hideAnimated:YES];
+    }
+}
+
+- (void)uploadImageArray:(NSMutableArray *)imageArray {
+    [self showhud];
+    NSMutableArray *imageDataArray = [NSMutableArray array];
+    for (UIImage *image in imageArray) {
+        NSData *imgData = [UIImage turnsImaegDataByImage:image];
+        [imageDataArray addObject:imgData];
+    }
+    [KSNetworkingManager multiImageUpload:KS_POST imgDataArray:imageDataArray success:^(NSArray * _Nonnull dics) {
+        [self removehub];
+        NSDictionary *dic = [dics lastObject];
+        if ([dic integerValueForKey:@"code"] == 200 && [dic boolValueForKey:@"status"]) {
+            NSMutableArray *urlArray = [NSMutableArray array];
+            for (NSDictionary *result in dics) {
+                NSDictionary *parm = [result dictionaryValueForKey:@"data"];
+                NSString *avatar = [parm stringValueForKey:@"url"];
+                [urlArray addObject:avatar];
+            }
+            NSString *attachments = [urlArray componentsJoinedByString:@","];
+            if (self.chooseFileParm) { // 回调
+                [self.chooseFileParm setValue:attachments forKey:@"fileUrl"];
+                [self postMessage:self.chooseFileParm];
+                self.chooseFileParm = nil;
+            }
+        }
+        else {
+            [self removehub];
+            [self MBPShow:MESSAGEKEY];
+        }
+    } faliure:^(NSError * _Nonnull error) {
+        [self removehub];
+    }];
+}
+
+#pragma mark --- 上传视频文件
+- (void)uploadVideoWithUrl:(NSString *)videoUrl {
+    // 取出视频第一帧
+    UIImage *previewImage = [self firstFrameWithVideoURL:[NSURL fileURLWithPath:videoUrl] size:CGSizeMake(1280, 720)];
+    __block NSString *imageUrl = @"";
+    if (previewImage) { // 如果有第一帧
+        NSData *imgData = [UIImage turnsImaegDataByImage:previewImage];
+        [KSNetworkingManager multiImageUpload:KS_POST imgDataArray:@[imgData] success:^(NSArray * _Nonnull dics) {
+            NSDictionary *dic = [dics lastObject];
+            if ([dic integerValueForKey:@"code"] == 200 && [dic boolValueForKey:@"status"]) {
+                NSDictionary *result = [dic dictionaryValueForKey:@"data"];
+                NSString *avatar = [result stringValueForKey:@"url"];
+                imageUrl = avatar;
+            }
+            else {
+                [self MBPShow:MESSAGEKEY];
+            }
+        } faliure:^(NSError * _Nonnull error) {
+            
+        }];
+    }
+    
+    // 上传视频
+    [self hudTipWillShow:YES];
+    NSData *fileData = [NSData dataWithContentsOfURL:[NSURL fileURLWithPath:videoUrl]];
+    [KSNetworkingManager videoFileUpload:KS_POST fileData:fileData progress:^(int64_t bytesWritten, int64_t totalBytes) {
+        dispatch_main_async_safe(^{
+            // 显示进度
+            if (self.HUD) {
+                self.HUD.progress = bytesWritten / totalBytes;// progress是回调进度
+            }
+        });
+    } success:^(NSDictionary * _Nonnull dic) {
+        [self hudTipWillShow:NO];
+        if ([dic integerValueForKey:@"code"] == 200 && [dic boolValueForKey:@"status"]) {
+            NSString *fileUrl = [[dic dictionaryValueForKey:@"data"] stringValueForKey:@"url"];
+            [self videoUploadCallback:fileUrl firstFrameImg:imageUrl];
+        }
+        else {
+            [self MBPShow:MESSAGEKEY];
+        }
+    } faliure:^(NSError * _Nonnull error) {
+        [self hudTipWillShow:NO];
+    }];
+}
+
+- (void)videoUploadCallback:(NSString *)remoteVideoUrl firstFrameImg:(NSString *)imgUrl {
+    if (self.chooseFileParm) { // 回调
+        [self.chooseFileParm setValue:remoteVideoUrl forKey:@"fileUrl"];
+        [self.chooseFileParm setValue:imgUrl forKey:@"firstFrameImg"];
+        [self postMessage:self.chooseFileParm];
+        self.chooseFileParm = nil;
+    }
+}
+
+#pragma mark ---- 获取图片第一帧
+- (UIImage *)firstFrameWithVideoURL:(NSURL *)url size:(CGSize)size
+{
+    // 获取视频第一帧
+    NSDictionary *opts = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:NO] forKey:AVURLAssetPreferPreciseDurationAndTimingKey];
+    AVURLAsset *urlAsset = [AVURLAsset URLAssetWithURL:url options:opts];
+    AVAssetImageGenerator *generator = [AVAssetImageGenerator assetImageGeneratorWithAsset:urlAsset];
+    generator.appliesPreferredTrackTransform = YES;
+    generator.maximumSize = CGSizeMake(size.width, size.height);
+    NSError *error = nil;
+    CGImageRef imgRef = [generator copyCGImageAtTime:CMTimeMake(0, 10) actualTime:NULL error:&error];
+    if (imgRef) {
+        UIImage *image = [UIImage imageWithCGImage:imgRef];
+        CGImageRelease(imgRef);
+        return image;
+    }
+    else {
+        return nil;
+    }
+}
+
+#pragma mark ---- UIDocumentPickerDelegate
+- (void)documentPickerWasCancelled:(UIDocumentPickerViewController *)controller {
+    
+}
+
+- (void)documentPicker:(UIDocumentPickerViewController *)controller didPickDocumentAtURL:(NSURL *)url {
+    NSArray *array = [[url absoluteString] componentsSeparatedByString:@"/"];
+    NSString *fileName = [array lastObject];
+    fileName = [fileName stringByRemovingPercentEncoding];
+    
+    if (self.fileChooseType == CHOOSETYPE_XML) {
+        if (![fileName hasSuffix:@".xml"]) {
+            [self MBPShow:@"请上传XML格式文件"];
+            return;
+        }
+    }
+    else {
+        if (![fileName hasSuffix:@".mp3"] && ![fileName hasSuffix:@".aac"]) {
+            [self MBPShow:@"暂不支持此格式!"];
+            return;
+        }
+    }
+    
+    // 获取文件大小
+//    CGFloat fileSize = [self getFileSize:url];
+//    if (fileSize > 10.0) {
+//        [self MBPShow:@"文件大小需小于10M"];
+//        return;
+//    }
+    
+    __block NSString * fileUrl = @"";
+    if ([KSICloudManager iCloudEnable]) {
+        [KSICloudManager downloadWithDocumentURL:url callBack:^(id obj) {
+            NSData *data = obj;
+            
+            //写入沙盒Documents
+             NSString *pathStr = [NSHomeDirectory() stringByAppendingString:[NSString stringWithFormat:@"/Documents/%@",fileName]];
+            [data writeToFile:pathStr atomically:YES];
+            
+            if (![[NSFileManager defaultManager] fileExistsAtPath:pathStr]) {
+                BOOL isSuccess = [data writeToFile:pathStr atomically:YES];
+                if (isSuccess) {
+                    fileUrl = pathStr;
+                }
+                else {
+                    [self MBPShow:@"写入文件错误!"];
+                }
+            }
+            else {
+                fileUrl = pathStr;
+            }
+            [self uploadFile:fileName fileUrl:pathStr];
+            
+        }];
+    }
+    else {
+        [self MBPShow:@"iCloud不可用!"];
+    }
+}
+
+- (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(), ^{
+        [self showhud];
+        NSString *suffix = [NSString stringWithFormat:@".%@",[[fileName componentsSeparatedByString:@"."] lastObject]];
+        NSData *fileData = [NSData dataWithContentsOfURL:[NSURL fileURLWithPath:fileUrl]];
+        [KSNetworkingManager fileUpload:KS_POST fileData:fileData fileSuffix:suffix success:^(NSDictionary * _Nonnull dic) {
+            [self removehub];
+            if ([dic integerValueForKey:@"code"] == 200 && [dic boolValueForKey:@"status"]) {
+                NSString *fileUrl = [[dic dictionaryValueForKey:@"data"] stringValueForKey:@"url"];
+                if (self.chooseFileParm) { // 回调
+                    [self.chooseFileParm setValue:fileUrl forKey:@"fileUrl"];
+                    [self postMessage:self.chooseFileParm];
+                    self.chooseFileParm = nil;
+                }
+            }
+            else {
+                [self MBPShow:MESSAGEKEY];
+            }
+            
+        } faliure:^(NSError * _Nonnull error) {
+            [self removehub];
+        }];
+        
+    });
+}
+
+- (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 - Navigation
 

+ 20 - 0
KulexiuForTeacher/KulexiuForTeacher/Common/Base/KSDocument.h

@@ -0,0 +1,20 @@
+//
+//  KSDocument.h
+//  TeacherDaya
+//
+//  Created by Kyle on 2020/11/26.
+//  Copyright © 2020 DayaMusic. All rights reserved.
+//
+
+#import <UIKit/UIKit.h>
+
+NS_ASSUME_NONNULL_BEGIN
+
+@interface KSDocument : UIDocument
+
+@property (nonatomic, strong) NSData *data;
+
+
+@end
+
+NS_ASSUME_NONNULL_END

+ 20 - 0
KulexiuForTeacher/KulexiuForTeacher/Common/Base/KSDocument.m

@@ -0,0 +1,20 @@
+//
+//  KSDocument.m
+//  TeacherDaya
+//
+//  Created by Kyle on 2020/11/26.
+//  Copyright © 2020 DayaMusic. All rights reserved.
+//
+
+#import "KSDocument.h"
+
+@implementation KSDocument
+
+- (BOOL)loadFromContents:(id)contents ofType:(NSString *)typeName error:(NSError * _Nullable __autoreleasing *)outError {
+    
+    self.data = contents;
+    
+    return YES;
+}
+
+@end

+ 17 - 0
KulexiuForTeacher/KulexiuForTeacher/Common/Base/KSDocumentViewController.h

@@ -0,0 +1,17 @@
+//
+//  KSDocumentViewController.h
+//  TeacherDaya
+//
+//  Created by Kyle on 2020/11/26.
+//  Copyright © 2020 DayaMusic. All rights reserved.
+//
+
+#import <UIKit/UIKit.h>
+
+NS_ASSUME_NONNULL_BEGIN
+
+@interface KSDocumentViewController : UIDocumentPickerViewController
+
+@end
+
+NS_ASSUME_NONNULL_END

+ 62 - 0
KulexiuForTeacher/KulexiuForTeacher/Common/Base/KSDocumentViewController.m

@@ -0,0 +1,62 @@
+//
+//  KSDocumentViewController.m
+//  TeacherDaya
+//
+//  Created by Kyle on 2020/11/26.
+//  Copyright © 2020 DayaMusic. All rights reserved.
+//
+
+#import "KSDocumentViewController.h"
+
+@interface KSDocumentViewController ()
+
+@end
+
+@implementation KSDocumentViewController
+
+- (void)viewDidLoad {
+    [super viewDidLoad];
+    // Do any additional setup after loading the view.
+    [[UITabBar appearance] setTranslucent:YES];
+}
+
+- (void)viewWillAppear:(BOOL)animated {
+    [super viewWillAppear:animated];
+    [[UIBarButtonItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:THEMECOLOR} forState:UIControlStateNormal];
+    [[UIButton appearance] setTintColor:THEMECOLOR];
+    
+    [UIImageView appearance].tintColor = THEMECOLOR;
+    [[UITabBar appearance] setTintColor:THEMECOLOR];
+    [UIView appearanceWhenContainedInInstancesOfClasses:@[[self class]]].tintColor = THEMECOLOR;
+}
+
+-(void)viewWillDisappear:(BOOL)animated
+{
+    [super viewWillDisappear:animated];
+    [[UIButton appearance] setTintColor:HexRGB(0x000000)];
+    [[UIBarButtonItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:HexRGB(0x000000)} forState:UIControlStateNormal];
+    [UIImageView appearance].tintColor = self.view.tintColor;
+    [[UITabBar appearance] setTintColor:self.view.tintColor];
+    [UIView appearanceWhenContainedInInstancesOfClasses:@[[self class]]].tintColor = self.view.tintColor;
+}
+
+- (void)viewDidDisappear:(BOOL)animated {
+    [super viewDidDisappear:animated];
+}
+ 
+-(void)dealloc
+{
+    [[UITabBar appearance] setTranslucent:NO];
+}
+
+/*
+#pragma mark - Navigation
+
+// In a storyboard-based application, you will often want to do a little preparation before navigation
+- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
+    // Get the new view controller using [segue destinationViewController].
+    // Pass the selected object to the new view controller.
+}
+*/
+
+@end

+ 23 - 0
KulexiuForTeacher/KulexiuForTeacher/Common/Base/KSICloudManager.h

@@ -0,0 +1,23 @@
+//
+//  KSICloudManager.h
+//  TeacherDaya
+//
+//  Created by Kyle on 2020/11/26.
+//  Copyright © 2020 DayaMusic. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+
+typedef void(^downloadBlock)(id _Nonnull obj);
+
+NS_ASSUME_NONNULL_BEGIN
+
+@interface KSICloudManager : NSObject
+
++ (BOOL)iCloudEnable;
+
++ (void)downloadWithDocumentURL:(NSURL*)url callBack:(downloadBlock)block;
+
+@end
+
+NS_ASSUME_NONNULL_END

+ 48 - 0
KulexiuForTeacher/KulexiuForTeacher/Common/Base/KSICloudManager.m

@@ -0,0 +1,48 @@
+//
+//  KSICloudManager.m
+//  TeacherDaya
+//
+//  Created by Kyle on 2020/11/26.
+//  Copyright © 2020 DayaMusic. All rights reserved.
+//
+
+#import "KSICloudManager.h"
+#import "KSDocument.h"
+
+@implementation KSICloudManager
+
++ (BOOL)iCloudEnable {
+    
+    NSFileManager *manager = [NSFileManager defaultManager];
+    
+    NSURL *url = [manager URLForUbiquityContainerIdentifier:nil];
+
+    if (url != nil) {
+        
+        return YES;
+    }
+    
+    NSLog(@"iCloud 不可用");
+    return NO;
+}
+
++ (void)downloadWithDocumentURL:(NSURL*)url callBack:(downloadBlock)block {
+    
+    KSDocument *iCloudDoc = [[KSDocument alloc] initWithFileURL:url];
+    
+    [iCloudDoc openWithCompletionHandler:^(BOOL success) {
+        if (success) {
+            
+            [iCloudDoc closeWithCompletionHandler:^(BOOL success) {
+                NSLog(@"关闭成功");
+            }];
+            
+            if (block) {
+                block(iCloudDoc.data);
+            }
+            
+        }
+    }];
+}
+
+@end

+ 12 - 0
KulexiuForTeacher/KulexiuForTeacher/Common/Base/KSNetworkingManager.h

@@ -49,6 +49,18 @@ NS_ASSUME_NONNULL_BEGIN
  */
 + (void)videoFileUpload:(NSString *)post fileData:(NSData *)fileData progress:(void(^)(int64_t bytesWritten,int64_t totalBytes))progress success:(void(^)(NSDictionary *dic))success faliure:(void(^)(NSError *error))faliure;
 
+#pragma mark --- 其他文件上传
+/**
+ 文件上传
+
+ @param post post
+ @param fileData 文件data
+ @param suffix  文件后缀
+ @param success 成功
+ @param faliure 失败
+ */
++ (void)fileUpload:(NSString *)post fileData:(NSData *)fileData fileSuffix:(NSString *)suffix success:(void(^)(NSDictionary *dic))success faliure:(void(^)(NSError *error))faliure;
+
 #pragma mark ----- 文件下载
 // 单文件下载
 + (void)downloadFileRequestWithFileUrl:(NSString *)url progress:(void (^)(int64_t bytesRead, int64_t totalBytes))progress success:(void(^)(NSURL *fileUrl))success faliure:(void (^)(NSError * error))faliure;

+ 16 - 0
KulexiuForTeacher/KulexiuForTeacher/Common/Base/KSNetworkingManager.m

@@ -336,6 +336,22 @@
     
     [self uploadFileWithFileData:fileData andWithUrl:url parameters:nil type:@".mp4" name:@"file" mimeType:[NSString stringWithFormat:@"Image/.mp4"] progress:progress success:success faliure:faliure];
 }
+#pragma mark --- 其他文件上传
+/**
+ 文件上传
+
+ @param post post
+ @param fileData 文件data
+ @param suffix  文件后缀
+ @param success 成功
+ @param faliure 失败
+ */
++ (void)fileUpload:(NSString *)post fileData:(NSData *)fileData fileSuffix:(NSString *)suffix success:(void(^)(NSDictionary *dic))success faliure:(void(^)(NSError *error))faliure {
+    [self configRequestMethodJSON];
+    NSString* url = [NSString stringWithFormat:@"%@%@",hostURL,@"/api-teacher/uploadFile"];
+    
+    [self uploadFileWithFileData:fileData andWithUrl:url parameters:nil type:suffix name:@"file" mimeType:[NSString stringWithFormat:@"Image/%@",suffix] progress:nil success:success faliure:faliure];
+}
 
 #pragma mark ---- 文件下载
 + (void)downloadFileRequestWithFileUrl:(NSString *)url progress:(void (^)(int64_t, int64_t))progress success:(void (^)(NSURL * _Nonnull))success faliure:(void (^)(NSError * _Nonnull))faliure {

+ 0 - 1
KulexiuForTeacher/KulexiuForTeacher/Common/Tools/Custom/KSMediaManager.m

@@ -13,7 +13,6 @@
 #import "TZVideoPlayerController.h"
 #import "TZImagePickerController.h"
 #import "UIImage+ResizeImage.h"
-//#import <UIDevice+YYAdd.h>
 #import <MobileCoreServices/MobileCoreServices.h>
 #import "KSPremissionAlert.h"
 

+ 22 - 16
KulexiuForTeacher/KulexiuForTeacher/Info.plist

@@ -2,26 +2,32 @@
 <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
 <plist version="1.0">
 <dict>
-	<key>UIUserInterfaceStyle</key>
-	<string>Light</string>
-	<key>NSAppleMusicUsageDescription</key>
-	<string>App需要您的同意访问媒体资料库权限,用于播放媒体服务</string>
-	<key>NSPhotoLibraryUsageDescription</key>
-	<string>App需要您的同意访问您的相册权限,用于您的图片课件上传服务</string>
-	<key>NSPhotoLibraryAddUsageDescription</key>
-	<string>App需要您的同意访问您的相册权限,用于您的图片课件上传服务</string>
-	<key>NSCameraUsageDescription</key>
-	<string>APP需要您的同意,访问您的相机,以便您正常使用上传图片、视频课程等服务</string>
-	<key>NSMicrophoneUsageDescription</key>
-	<string>App需要您的同意访问麦克风权限,用于您的语音服务、视频教学</string>
-	<key>UILaunchStoryboardName</key>
-	<string>LaunchScreen</string>
+	<key>CFBundleDocumentTypes</key>
+	<array>
+		<dict>
+			<key>CFBundleTypeName</key>
+			<string>Colexiu</string>
+			<key>LSHandlerRank</key>
+			<string>Default</string>
+			<key>LSItemContentTypes</key>
+			<array>
+				<string>com.adobe.pdf</string>
+				<string>com.microsoft.word.doc</string>
+				<string>com.microsoft.powerpoint.ppt</string>
+				<string>public.item</string>
+				<string>public.data</string>
+				<string>public.text</string>
+				<string>public.content</string>
+				<string>public.composite-content</string>
+				<string>public.audio</string>
+				<string>public.image</string>
+			</array>
+		</dict>
+	</array>
 	<key>NSAppTransportSecurity</key>
 	<dict>
 		<key>NSAllowsArbitraryLoads</key>
 		<true/>
 	</dict>
-	<key>CFBundleDevelopmentRegion</key>
-	<string>$(DEVELOPMENT_LANGUAGE)</string>
 </dict>
 </plist>

+ 1 - 1
KulexiuForTeacher/KulexiuForTeacher/Module/Mine/VideoCourse/Controller/VideoCourseViewController.m

@@ -65,7 +65,7 @@
 
 - (void)rightBtnClick { // 创建视频课
     KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
-    webCtrl.url = [NSString stringWithFormat:@"%@%@", WEBHOST, @"/#/teacherCert"];
+    webCtrl.url = [NSString stringWithFormat:@"%@%@", WEBHOST, @"/#/videoCreate"];
     [self.navigationController pushViewController:webCtrl animated:YES];
 }