1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035 |
- //
- // KSBaseWKWebViewController.m
- // KulexiuForTeacher
- //
- // Created by Kyle on 2022/3/17.
- //
- #import "KSBaseWKWebViewController.h"
- #import "WebViewBaseConfig.h" // 基础配置
- #import <UIDevice+TFDevice.h> // 横竖屏
- // 其他web
- #import "KSLocalWebViewController.h"
- #import "KSCloudWebManager.h"
- #import "AppDelegate+AppService.h"
- #import "UserInfoManager.h"
- #import "KSMediaManager.h"
- #import "KSUMShareManager.h"
- #import "KSOrderManager.h"
- #import "KSEnterLiveroomManager.h"
- // 保存文件
- #import <KSICloudManager.h>
- #import <KSDocumentViewController.h>
- // 聊天页面
- #import "KSChatConversationViewController.h"
- #import "KSGroupConversationController.h"
- #import "AddressListViewController.h"
- // 视频封面选择
- #import "KSVideoCropViewController.h"
- // 错误刷新web 页面
- #import "KSWebLoadRefreshView.h"
- #import "KSNewAlertView.h"
- #import "KSLogManager.h"
- #import "KSSourceDownloadAlert.h"
- #import "KSPlatformDownloadAlert.h"
- #import "KSAudioSaveAlert.h"
- // 加载UI
- #import "AccompanyLoadingView.h"
- typedef NS_ENUM(NSInteger, CHOOSETYPE) {
- CHOOSETYPE_XML,
- CHOOSETYPE_MIDI,
- CHOOSETYPE_MP3,
- CHOOSETYPE_ALL,
- };
- @interface KSBaseWKWebViewController ()<UIDocumentPickerDelegate,UIDocumentInteractionControllerDelegate>
- @property (nonatomic, assign) BOOL isOutLink; // 外部链接
- @property (nonatomic,weak) CALayer *progressLayer;
- @property (nonatomic, assign) BOOL hasModify;
- @property (nonatomic, assign) BOOL hasChangeSource; // 是否切换了亮屏,横屏等配置
- /// 选择本地文件 parm
- @property (nonatomic, strong) NSMutableDictionary *chooseFileParm;
- @property (nonatomic, strong) KSMediaManager *mediaManager;
- @property (strong, nonatomic) MBProgressHUD *HUD;
- @property (nonatomic, assign) CHOOSETYPE fileChooseType;
- @property (nonatomic, strong) NSString *bucketName;
- @property (nonatomic, assign) BOOL isFirstLoad;
- @property (nonatomic, strong) KSWebLoadRefreshView *errorView;
- @property (nonatomic, strong) KSUMShareManager *shareManager;
- @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;
- @property (nonatomic, strong) AccompanyLoadingView *customLoading;
- @end
- @implementation KSBaseWKWebViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
- self.ks_prefersNavigationBarHidden = YES; // 隐藏导航栏,其他事件额外处理
- [self initWebView];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(operationDealCallbackMessage:) name:DEALCALLBACKNOTICIFATION object:nil];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(backLoginView) name:@"liveroomBackRefresh" object:nil];
- self.isFirstLoad = YES;
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(captureViewTips:) name:UIScreenCapturedDidChangeNotification object:nil];
- }
- - (void)operationDealCallbackMessage:(NSNotification *)notification {
- NSString *status = [notification object];
- NSMutableDictionary *sendParm = [NSMutableDictionary dictionary];
- [sendParm setValue:@"paymentOperation" forKey:@"api"];
- NSMutableDictionary *content = [NSMutableDictionary dictionary];
- [content setValue:status forKey:@"status"];
- [sendParm setValue:content forKey:@"content"];
- [self postMessage:sendParm];
- }
- - (void)setParmDic:(NSDictionary *)parmDic {
- _parmDic = parmDic;
- _hasChangeSource = YES;
- BOOL isOpenLight = [parmDic ks_boolValueForKey:@"isOpenLight"];
- [[UIApplication sharedApplication] setIdleTimerDisabled:isOpenLight];
- // 横竖屏
- NSInteger orientation = [parmDic ks_integerValueForKey:@"orientation"];
-
- BOOL isLandScape = orientation == 0 ? YES : NO;
- self.ks_landScape = isLandScape;
- [self changeOrientation:isLandScape];
- }
- - (void)changeOrientation:(BOOL)isLandScape {
- if (isLandScape) {
- // 切换到横屏
- if (IS_IPAD) {
- self.zh_statusBarHidden = YES;
- }
- AppDelegate* delegate = (AppDelegate*)[UIApplication sharedApplication].delegate;
- delegate.allowAutoRotate = YES;
- [UIDevice switchNewOrientation:UIInterfaceOrientationLandscapeRight inController:self];
- }
- else {
- if (IS_IPAD) {
- self.zh_statusBarHidden = NO;
- }
- AppDelegate* delegate = (AppDelegate*)[UIApplication sharedApplication].delegate;
- delegate.allowAutoRotate = NO;
- [UIDevice switchNewOrientation:UIInterfaceOrientationPortrait inController:self];
- }
- }
- - (void)viewWillAppear:(BOOL)animated {
- [super viewWillAppear:animated];
- if (self.needReload) {
- self.needReload = NO;
- [self.myWebView reload];
- }
- if (_hasChangeSource) {
- [self setParmDic:self.parmDic];
- }
- if (self.isFirstLoad == NO) {
- [self sendResumeMessage];
- }
- self.isFirstLoad = NO;
-
- [self checkCaptured];
- }
- - (void)sendResumeMessage {
-
- NSMutableDictionary *parm = [NSMutableDictionary dictionary];
- [parm setValue:@"webViewOnResume" forKey:@"api"];
- [self postMessage:parm];
- }
- - (void)viewWillDisappear:(BOOL)animated {
- [super viewWillDisappear:animated];
- BOOL isBack = [self isViewPopDismiss];
- if (isBack) {
- if (self.preCtrl) {
- if (self.ks_landScape != self.preCtrl.ks_landScape) {
- [self changeOrientation:self.preCtrl.ks_landScape];
- }
- }
- if (![self.preCtrl isKindOfClass:[KSBaseWKWebViewController class]]) {
- [[UIApplication sharedApplication] setIdleTimerDisabled:NO];
- }
- }
- else {
- if ([self.presentedViewController isKindOfClass:NSClassFromString(@"TZImagePickerController")] || [self.presentedViewController isKindOfClass:NSClassFromString(@"RSKImageCropViewController")] || [self.presentedViewController isKindOfClass:NSClassFromString(@"KSVideoCropViewController")]) {
- NSLog(@"-----");
- }
- else {
- KSBaseViewController *nextCtrl = [self getNextViewController];
- if (nextCtrl) {
- if (nextCtrl.ks_landScape != self.ks_landScape) {
- [self changeOrientation:NO];
- }
- }
- }
- }
- }
- - (void)initWebView {
- [self.scrollView removeFromSuperview];
-
- if (_myWebView == nil) {
-
- WKWebViewConfiguration *config = [[WKWebViewConfiguration alloc] init];
- config.selectionGranularity = WKSelectionGranularityDynamic;
- config.allowsInlineMediaPlayback = YES;
- config.mediaTypesRequiringUserActionForPlayback = NO;
- config.processPool = [KSBaseWKWebViewController singleWkProcessPool];
- config.websiteDataStore = [WKWebsiteDataStore defaultDataStore];
- [self configUserAgent:config];
- //自定义的WKScriptMessageHandler 是为了解决内存不释放的问题
- WeakWebViewScriptMessageDelegate *weakScriptMessageDelegate = [[WeakWebViewScriptMessageDelegate alloc] initWithDelegate:self];
- //这个类主要用来做native与JavaScript的交互管理
- WKUserContentController * wkUController = [[WKUserContentController alloc] init];
- [wkUController addScriptMessageHandler:weakScriptMessageDelegate name:SCRIPT_NAME];
- config.userContentController = wkUController;
-
- WKPreferences *preferences = [WKPreferences new];
- // 是否支出javaScript
- preferences.javaScriptEnabled = YES;
- //不通过用户交互,是否可以打开窗口
- preferences.javaScriptCanOpenWindowsAutomatically = YES;
- config.preferences = preferences;
- _myWebView = [[WKWebView alloc] initWithFrame:CGRectZero configuration:config];
- _myWebView.UIDelegate = self;
- _myWebView.navigationDelegate = self;
- _myWebView.scrollView.bounces = NO;
- _myWebView.scrollView.showsVerticalScrollIndicator = NO;
- _myWebView.scrollView.showsHorizontalScrollIndicator = NO;
- // _myWebView.allowsBackForwardNavigationGestures = YES;
- [self.view addSubview:_myWebView];
- #ifdef DEBUG
- if (@available(iOS 16.4, *)) {
- _myWebView.inspectable = YES;
- }
- #endif
- // 加载进度条和title
- [_myWebView addObserver:self forKeyPath:@"estimatedProgress" options:NSKeyValueObservingOptionNew context:nil];
- [_myWebView addObserver:self forKeyPath:@"title" options:NSKeyValueObservingOptionNew context:NULL];
- [self.view addSubview:_myWebView];
- [_myWebView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.mas_equalTo(self.view);
- make.top.mas_equalTo(self.view.mas_top);
- make.bottom.mas_equalTo(self.view.mas_bottom);
- }];
- _myWebView.scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
- [self setupProgress];
- // 修改userAgent
- [self loadRequest];
- }
- else {
- [_myWebView reload];
- }
- }
- - (void)configUserAgent:(WKWebViewConfiguration *)config {
- NSString *oldUserAgent = config.applicationNameForUserAgent;
- NSString *newAgent = [NSString stringWithFormat:@"%@ %@ %@",oldUserAgent,AGENT_NAME,AGENT_DOMAIN];
- config.applicationNameForUserAgent = newAgent;
- }
- - (void)loadRequest {
-
- NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:self.url] cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:60.0f];
- [self.myWebView loadRequest:request];
- }
- - (NSString *)url {
- if (_url) {
- if ([_url containsString:@"Authorization="]) {
- NSRange range = [_url rangeOfString:@"Authorization="];
- if (range.location != NSNotFound) {
- _url = [_url substringToIndex:range.location-1];
- }
- }
- NSString *sepectString = [_url containsString:@"?"] ? @"&" : @"?";
- NSString *tokenStr = UserDefault(TokenKey);
- if (![NSString isEmptyString:tokenStr]) {
- NSString *token = [[NSString stringWithFormat:@"Authorization=%@ %@", UserDefault(Token_type), tokenStr] stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
- _url = [NSString stringWithFormat:@"%@%@%@",_url, sepectString, token];
- }
- }
- return _url;
- }
- #pragma mark --- 返回按钮的处理
- - (void)backPreViewAction {
- [self.myWebView stopLoading];
- if (_backRootView) {
- [self.navigationController popToRootViewControllerAnimated:NO];
- return;
- }
- else if (_isBackPreView) {
- [self.navigationController popViewControllerAnimated:YES];
- return;
- }
- else {
- [self.navigationController popViewControllerAnimated:YES];
- }
- }
- - (void)backAction {
- [self.myWebView stopLoading];
- if (_backRootView) {
- [self.navigationController popToRootViewControllerAnimated:NO];
- return;
- }
- else if (_isBackPreView) {
- [self.navigationController popViewControllerAnimated:YES];
- return;
- }
- else if ([self.myWebView canGoBack]) {
- [self.myWebView goBack];
- }
- else {
- [self.navigationController popViewControllerAnimated:YES];
- }
- }
- #pragma mark - WKScriptMessageHandler
- - (void)userContentController:(WKUserContentController *)userContentController
- didReceiveScriptMessage:(WKScriptMessage *)message {
- if ([message.name isEqualToString:SCRIPT_NAME]) {
- NSDictionary *parm = [self convertJsonStringToNSDictionary:message.body];
- // 回到主线程
- dispatch_async(dispatch_get_main_queue(), ^{
- [self handleScriptMessageSource:parm];
- });
- }
- }
- - (void)handleScriptMessageSource:(NSDictionary *)parm {
- if ([[parm ks_stringValueForKey:@"api"] isEqualToString:@"back"]) { // 返回
- [self backPreViewAction];
- }
- else if ([[parm ks_stringValueForKey:@"api"] isEqualToString:@"goBack"]) { // 逐级返回
- [self backAction];
- }
- else if ([[parm ks_stringValueForKey:@"api"] isEqualToString:@"login"]) {
- // 回到登录页面
- [self backLoginView];
- }
- else if ([[parm ks_stringValueForKey:@"api"] isEqualToString:@"openWebView"]) { // 打开新页面
- NSDictionary *valueDic = [parm ks_dictionaryValueForKey:@"content"];
-
- KSBaseWKWebViewController *detailCtrl = [[KSBaseWKWebViewController alloc] init];
- detailCtrl.url = [valueDic ks_stringValueForKey:@"url"];
- detailCtrl.parmDic = valueDic;
- NSInteger orientation = [valueDic ks_integerValueForKey:@"orientation"];
- BOOL isLandScape = orientation == 0 ? YES : NO;
- detailCtrl.ks_landScape = isLandScape;
- [self postMessage:parm];
- [self.navigationController pushViewController:detailCtrl animated:YES];
- }
- else if ([[parm ks_stringValueForKey:@"api"] isEqualToString:@"setRequestedOrientation"]) {
- NSDictionary *valueDic = [parm ks_dictionaryValueForKey:@"content"];
- // 横竖屏
- NSInteger orientation = [valueDic ks_integerValueForKey:@"orientation"];
- BOOL isLandScape = orientation == 0 ? YES : NO;
- self.ks_landScape = isLandScape;
- [self changeOrientation:isLandScape];
-
- }
- else if ([[parm ks_stringValueForKey:@"api"] isEqualToString:@"keepScreenLongLight"]) {
- NSDictionary *valueDic = [parm ks_dictionaryValueForKey:@"content"];
- BOOL isOpenLight = [valueDic ks_boolValueForKey:@"isOpenLight"];
- [[UIApplication sharedApplication] setIdleTimerDisabled:isOpenLight];
- }
- else if ([[parm ks_stringValueForKey:@"api"] isEqualToString:@"downLoad"]) {
- NSDictionary *valueDic = [parm ks_dictionaryValueForKey:@"content"];
- if ([valueDic ks_stringValueForKey:@"PDF"]) {
- NSString *url = [valueDic ks_stringValueForKey:@"downloadUrl"];
- [KSNetworkingManager downloadFileRequestWithFileUrl:url progress:^(int64_t bytesRead, int64_t totalBytes) {
- } success:^(NSURL * _Nonnull fileUrl) {
- [LOADING_MANAGER KSShowMsg:@"下载成功" promptCompletion:^{
- [self displaySource:fileUrl];
- }];
- } faliure:^(NSError * _Nonnull error) {
- }];
- }
- }
- 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;
- NSMutableDictionary *valueDic = [NSMutableDictionary dictionaryWithDictionary:[parm ks_dictionaryValueForKey:@"content"]];
- [valueDic setValue:@(isShapedScreen) forKey:@"isSpecialShapedScreen"];
- [valueDic setValue:@(iPhoneXSafeTopMargin*2) forKey:@"notchHeight"];
- NSMutableDictionary *sendParm = [NSMutableDictionary dictionaryWithDictionary:parm];
- [sendParm setValue:valueDic forKey:@"content"];
- [self postMessage:sendParm];
- }
- else if ([[parm ks_stringValueForKey:@"api"] isEqualToString:@"getToken"]) {
- NSMutableDictionary *valueDic = [NSMutableDictionary dictionaryWithDictionary:[parm ks_dictionaryValueForKey:@"content"]];
- [valueDic setValue:UserDefault(Token_type) forKey:@"tokenType"];
- [valueDic setValue:UserDefault(TokenKey) forKey:@"accessToken"];
- NSMutableDictionary *sendParm = [NSMutableDictionary dictionaryWithDictionary:parm];
- [sendParm setValue:valueDic forKey:@"content"];
- [self postMessage:sendParm];
- }
-
- else if ([[parm ks_stringValueForKey:@"api"] isEqualToString:@"openAccompanyWebView"]) { // 打开伴奏
- NSDictionary *valueDic = [parm ks_dictionaryValueForKey:@"content"];
-
- NSMutableDictionary *webParm = [NSMutableDictionary dictionaryWithDictionary:valueDic];
- NSString *url = [valueDic ks_stringValueForKey:@"url"];
- [webParm setValue:url forKey:@"url"];
- [CLOUDWEB_MANAGER configCloudWebSource];
- [CLOUDWEB_MANAGER showWebView:webParm fromController:(CustomNavViewController *)self.navigationController];
- }
- else if ([[parm ks_stringValueForKey:@"api"] isEqualToString:@"checkAlbum"]) { // 判断权限
- [RecordCheckManager checkPhotoLibraryPremissionAvaiableCallback:^(PREMISSIONTYPE type) {
- if (type == PREMISSIONTYPE_YES) {
- [self postMessage:parm];
- }
- else {
- [self showAlertWithMessage:@"请开启相册访问权限" type:CHECKDEVICETYPE_CAMREA];
- }
- }];
- }
- else if ([[parm ks_stringValueForKey:@"api"] isEqualToString:@"shareAchievements"]) { // 分享
- //
- [self shareFunctionWithParm:parm];
- }
- else if ([[parm ks_stringValueForKey:@"api"] isEqualToString:@"setStatusBarTextColor"]) { // 设置状态栏颜色
- NSDictionary *valueDic = [parm ks_dictionaryValueForKey:@"content"];
- BOOL whiteColor = [valueDic ks_boolValueForKey:@"statusBarTextColor"];
- if (whiteColor) {
- [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
- }
- else {
- if (@available(iOS 13.0, *)) {
- [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDarkContent;
- } else {
- // Fallback on earlier versions
- [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault;
- }
- }
- }
- else if ([[parm ks_stringValueForKey:@"api"] isEqualToString:@"getNavHeight"]) { // 获取状态栏高度和 title heigt
- NSDictionary *valueDic = [parm ks_dictionaryValueForKey:@"content"];
- [valueDic setValue:[NSNumber numberWithFloat:STATUS_GAP*2] forKey:@"navHeight"];
- [valueDic setValue:@(44*2) forKey:@"titleHeight"];
- [parm setValue:valueDic forKey:@"content"];
- [self postMessage:parm];
- }
-
- else if ([[parm ks_stringValueForKey:@"api"] isEqualToString:@"joinChatGroup"]) {
- NSDictionary *valueDic = [parm ks_dictionaryValueForKey:@"content"];
- NSString *targetId = [valueDic ks_stringValueForKey:@"id"];
- if ([[valueDic ks_stringValueForKey:@"type"] isEqualToString:@"single"]) { // 单聊
-
- TUIChatConversationModel *model = [[TUIChatConversationModel alloc] init];
- model.userID = targetId;
- KSChatConversationViewController *ctrl = [[KSChatConversationViewController alloc] init];
- ctrl.conversation = model;
- [self.navigationController pushViewController:ctrl animated:YES];
- }
- else if ([[valueDic ks_stringValueForKey:@"type"] isEqualToString:@"multi"]) { // 群聊
- if ([NSString isEmptyString:targetId]) {
- [LOADING_MANAGER MBShowAUTOHidingInWindow:@"报名未结束,暂无群组"];
- return;
- }
- TUIChatConversationModel *model = [[TUIChatConversationModel alloc] init];
- model.groupID = targetId;
- KSGroupConversationController *ctrl = [[KSGroupConversationController alloc] init];
- ctrl.conversation = model;
- [self.navigationController pushViewController:ctrl animated:YES];
- }
- }
- else if ([[parm ks_stringValueForKey:@"api"] isEqualToString:@"chooseFile"]) {
- NSDictionary *valueDic = [parm ks_dictionaryValueForKey:@"content"];
- self.chooseFileParm = [NSMutableDictionary dictionaryWithDictionary:valueDic];
- NSString *typeStr = [valueDic ks_stringValueForKey:@"type"];
- NSInteger maxCount = [valueDic ks_integerValueForKey:@"max"];
- NSString *bucket = [valueDic ks_stringValueForKey:@"bucket"];
- [self chooseFileWithType:typeStr maxNumber:maxCount bucket:bucket];
- }
- else if ([[parm ks_stringValueForKey:@"api"] isEqualToString:@"setAddress"]) { // 跳转地址选择
- AddressListViewController *ctrl = [[AddressListViewController alloc] init];
- ctrl.isChooseAddress = YES;
- MJWeakSelf;
- [ctrl chooseAddressAction:^(AddressListModel * _Nonnull model) {
- [weakSelf sendAddressAction:model];
- }];
- [self.navigationController pushViewController:ctrl animated:YES];
- }
- else if ([[parm ks_stringValueForKey:@"api"] isEqualToString:@"savePicture"]) { // 保存图片到相册
- // 判断相册权限
- [RecordCheckManager checkPhotoLibraryPremissionAvaiableCallback:^(PREMISSIONTYPE type) {
- if (type == PREMISSIONTYPE_YES) {
- NSDictionary *valueDic = [parm ks_dictionaryValueForKey:@"content"];
- NSString *base64String = [valueDic ks_stringValueForKey:@"base64"];
- UIImage *saveImage = [self imageWithBase64String:base64String];
- [[TZImageManager manager] savePhotoWithImage:saveImage completion:^(PHAsset *asset, NSError *error) {
- if (!error) {
- [self savePicCallback:[valueDic ks_stringValueForKey:@"uuid"] isSuccess:YES];
- }
- else {
- [self savePicCallback:[valueDic ks_stringValueForKey:@"uuid"] isSuccess:NO];
- }
- }];
- }
- else {
- [self showAlertWithMessage:@"请开启相册访问权限" type:CHECKDEVICETYPE_CAMREA];
- }
- }];
- }
- else if ([[parm ks_stringValueForKey:@"api"] isEqualToString:@"getVersion"]) {
- NSDictionary *valueDic = [parm ks_dictionaryValueForKey:@"content"];
- NSMutableDictionary *sendParm = [NSMutableDictionary dictionary];
- [parm setValue:@"getVersion" forKey:@"api"];
- NSMutableDictionary *content = [NSMutableDictionary dictionary];
- [content setValue:[USER_MANAGER getCurrentVersion] forKey:@"version"];
- [content setValue:[valueDic ks_stringValueForKey:@"uuid"] forKey:@"uuid"];
- [sendParm setValue:content forKey:@"content"];
- [self postMessage:sendParm];
- }
- else if ([[parm ks_stringValueForKey:@"api"] isEqualToString:@"getDeviceStatus"]) {
- NSDictionary *valueDic = [parm ks_dictionaryValueForKey:@"content"];
- NSString *type = [valueDic ks_stringValueForKey:@"type"];
- if ([type isEqualToString:@"video"]) {
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- NSString *status;
- if ([self checkIsCaptured]) {
- status = @"1";
- }
- else {
- status = @"0";
- }
- NSMutableDictionary *sendParm = [NSMutableDictionary dictionary];
- [sendParm setValue:@"getDeviceStatus" forKey:@"api"];
- NSMutableDictionary *content = [NSMutableDictionary dictionary];
- [content setValue:[valueDic ks_stringValueForKey:@"type"] forKey:@"type"];
- [content setValue:[valueDic ks_stringValueForKey:@"uuid"] forKey:@"uuid"];
- [content setValue:status forKey:@"status"];
- [sendParm setValue:content forKey:@"content"];
- [self postMessage:sendParm];
- });
- }
- }
- else if ([[parm ks_stringValueForKey:@"api"] isEqualToString:@"callPhone"]) {
- NSDictionary *valueDic = [parm ks_dictionaryValueForKey:@"content"];
- NSString *phone = [valueDic ks_stringValueForKey:@"phone"];
- [self CallPhoneWith:phone];
- }
- else if ([[parm ks_stringValueForKey:@"api"] isEqualToString:@"setCache"]) {
- NSDictionary *valueDic = [parm ks_dictionaryValueForKey:@"content"];
- NSString *key = [valueDic ks_stringValueForKey:@"key"];
- NSString *value = [valueDic ks_stringValueForKey:@"value"];
- UserDefaultSetObjectForKey(value, key);
- }
- else if ([[parm ks_stringValueForKey:@"api"] isEqualToString:@"getCache"]) {
- NSDictionary *valueDic = [parm ks_dictionaryValueForKey:@"content"];
- NSString *key = [valueDic ks_stringValueForKey:@"key"];
- NSString *value = UserDefault(key);
-
- NSMutableDictionary *parm = [NSMutableDictionary dictionaryWithDictionary:valueDic];
- [parm setValue:value forKey:@"value"];
- NSMutableDictionary *sendParm = [NSMutableDictionary dictionary];
- [sendParm setValue:@"getCache" forKey:@"api"];
- [sendParm setValue:parm forKey:@"content"];
- [self postMessage:sendParm];
- }
- else if ([[parm ks_stringValueForKey:@"api"] isEqualToString:@"isInstall"]) {
- NSDictionary *valueDic = [parm ks_dictionaryValueForKey:@"content"];
- NSString *type = [valueDic ks_stringValueForKey:@"type"];
-
- NSURL *url = [NSURL URLWithString:type];
- BOOL canOpen = [[UIApplication sharedApplication] canOpenURL:url];
- NSInteger installStatus = canOpen ? 1 : 0;
-
- NSMutableDictionary *parm = [NSMutableDictionary dictionaryWithDictionary:valueDic];
- [parm setValue:@(installStatus) forKey:@"installStatus"];
- NSMutableDictionary *sendParm = [NSMutableDictionary dictionary];
- [sendParm setValue:@"isInstall" forKey:@"api"];
- [sendParm setValue:parm forKey:@"content"];
- [self postMessage:sendParm];
- }
- else if ([[parm ks_stringValueForKey:@"api"] isEqualToString:@"openApp"]) {
- NSDictionary *valueDic = [parm ks_dictionaryValueForKey:@"content"];
- NSString *type = [valueDic ks_stringValueForKey:@"type"];
-
- NSURL *url = [NSURL URLWithString:type];
- if ([[UIApplication sharedApplication] canOpenURL:url]) {
- [[UIApplication sharedApplication] openURL:url options:@{} completionHandler:nil];
- }
- }
-
- else if ([[parm ks_stringValueForKey:@"api"] isEqualToString:@"downloadApp"]) {
- NSDictionary *valueDic = [parm ks_dictionaryValueForKey:@"content"];
- NSString *openUrl = [valueDic ks_stringValueForKey:@"url"];
- bool can = [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:openUrl]];
- if(can){
- [[UIApplication sharedApplication] openURL:[NSURL URLWithString:openUrl] options:@{} completionHandler:nil];
- }
- }
- else if ([[parm ks_stringValueForKey:@"api"] isEqualToString:@"shareTripartite"]) { // 分享到微信
- [self shareToWeChat:parm];
- }
- else if ([[parm ks_stringValueForKey:@"api"] isEqualToString:@"saveFile"]) { // 下载资源
- NSDictionary *content = [parm ks_dictionaryValueForKey:@"content"];
- NSString *url = [content ks_stringValueForKey:@"url"];
- [self downFile:url];
- }
- else if ([[parm ks_stringValueForKey:@"api"] isEqualToString:@"videoCrop"]) { // 选择封面
- NSDictionary *content = [parm ks_dictionaryValueForKey:@"content"];
- KSVideoCropViewController *ctrl = [[KSVideoCropViewController alloc] init];
- NSString *videoUrl = [content ks_stringValueForKey:@"url"];
- [ctrl configWithVideoRemoteUrl:videoUrl];
- [ctrl changeLandScape];
- MJWeakSelf;
- [ctrl chooseCropImageCallback:^(UIImage * _Nonnull cropImage) {
- [weakSelf videCropImage:cropImage content:content];
- }];
- ctrl.modalPresentationStyle = UIModalPresentationFullScreen;
- [self.navigationController presentViewController:ctrl animated:YES completion:nil];
- }
- else if ([[parm ks_stringValueForKey:@"api"] isEqualToString:@"paymentOrder"]) {
- NSDictionary *content = [parm ks_dictionaryValueForKey:@"content"];
- NSString *channel = [content ks_stringValueForKey:@"payChannel"];
- if ([channel isEqualToString:@"ali_app"]) {
- NSString *infoMessage = [content ks_stringValueForKey:@"payInfo"];
- [KSOrderManager dealWithAliSDK:infoMessage];
- }
- else if ([channel isEqualToString:@"wx_app"]) {
- NSString *infoMessage = [content ks_stringValueForKey:@"payInfo"];
- [KSOrderManager dealWithWXSDK:infoMessage];
- }
- }
- else if ([[parm ks_stringValueForKey:@"api"] isEqualToString:@"joinLiveRoom"]) { // 进入直播间
- NSDictionary *valueDic = [parm ks_dictionaryValueForKey:@"content"];
- NSString *roomId = [valueDic ks_stringValueForKey:@"roomId"];
- [LOADING_MANAGER showHUD];
- [KSEnterLiveroomManager joinLiveWithRoomId:roomId inController:(CustomNavViewController *)self.navigationController callback:^{
- [LOADING_MANAGER removeHUD];
- }];
- }
- else if ([[parm ks_stringValueForKey:@"api"] isEqualToString:@"setEventTracking"]) {
- NSString *type = [[parm ks_dictionaryValueForKey:@"content"] ks_stringValueForKey:@"type"];
- [USER_MANAGER sendUMEvent:type];
- }
- // 课件相关
- else if ([[parm ks_stringValueForKey:@"api"] isEqualToString:@"getCourseFilePath"]) { // 课件资源查询
- NSDictionary *valueDic = [parm ks_dictionaryValueForKey:@"content"];
- NSString *localPath = [COURSEWARE_MANAGER queryFileUrlWithParm:valueDic];
- BOOL isServiceStart = [AppDelegate shareAppDelegate].httpServer.isRunning;
- if (![NSString isEmptyString:localPath] && isServiceStart) {
- localPath = [[localPath componentsSeparatedByString:@"CoursewarePath/"] lastObject];
- localPath = [NSString stringWithFormat:@"%@%@/%@",@"http://localhost:",[AppDelegate shareAppDelegate].serverPort,localPath];
- NSMutableDictionary *contentParm = [NSMutableDictionary dictionaryWithDictionary:valueDic];
- [contentParm setValue:localPath forKey:@"localPath"];
- NSMutableDictionary *sendParm = [NSMutableDictionary dictionary];
- [sendParm setValue:@"getCourseFilePath" forKey:@"api"];
- [sendParm setValue:contentParm forKey:@"content"];
- [self postMessage:sendParm];
- }
- else {
- [self postMessage:parm];
- }
- }
- else if ([[parm ks_stringValueForKey:@"api"] isEqualToString:@"checkCoursewareCache"]) {
- MJWeakSelf;
- [COURSEWARE_MANAGER checkCourseCacheStatus:parm callback:^(NSDictionary * _Nonnull parm) {
- [weakSelf postMessage:parm];
- }];
- }
- else if ([[parm ks_stringValueForKey:@"api"] isEqualToString:@"downloadCoursewareToCache"]) {
- NSDictionary *valueDic = [parm ks_dictionaryValueForKey:@"content"];
- NSString *lessonCoursewareDetailId = [[valueDic ks_dictionaryValueForKey:@"data"] ks_stringValueForKey:@"lessonCoursewareDetailId"];
- if (COURSEWARE_MANAGER.isDownloading) {
- if ([lessonCoursewareDetailId isEqualToString:COURSEWARE_MANAGER.lessonCoursewareDetailId]) {
- [LOADING_MANAGER MBShowAUTOHidingInWindow:@"当前已有课件资源下载中"];
- [self downloadWithParm:parm];
- }
- else {
- [LOADING_MANAGER MBShowAUTOHidingInWindow:@"当前已有课件资源下载中"];
- NSMutableDictionary *contentParm = [NSMutableDictionary dictionary];
- [contentParm setValue:@(3) forKey:@"status"];
- [contentParm setValue:@(0) forKey:@"progress"];
- [contentParm setValue:lessonCoursewareDetailId forKey:@"lessonCoursewareDetailId"];
- NSMutableDictionary *sendParm = [NSMutableDictionary dictionary];
- [sendParm setValue:@"downloadCoursewareToCache" forKey:@"api"];
- [sendParm setValue:contentParm forKey:@"content"];
- [self postMessage:sendParm];
- }
- }
- else {
- if ([self isWiFiEnable] == NO) {
- self.wifiAlert = [KSNewAlertView shareInstance];
- MJWeakSelf;
- [self.wifiAlert configTitle:@"提示" descMessage:@"当前非Wi-Fi环境,是否开始下载?" leftButtonTitle:@"取消" rightButtonTitle:@"确认" leftButtonAction:^{
-
- } rightButtonAction:^{
- [weakSelf downloadWithParm:parm];
- }];
- [self.wifiAlert showAlert];
- }
- else {
- [self downloadWithParm:parm];
- }
- }
- }
- else if ([[parm ks_stringValueForKey:@"api"] isEqualToString:@"cancelDownloadCourseware"]) { // 取消下载课件
- if (COURSEWARE_MANAGER.isDownloading) { // 如果在下载 取消
- [COURSEWARE_MANAGER cancleDownloadCourseware];
- }
- NSMutableDictionary *content = [NSMutableDictionary dictionaryWithDictionary:[parm ks_dictionaryValueForKey:@"content"]];
- [content setValue:@(YES) forKey:@"status"];
- NSMutableDictionary *sendParm = [NSMutableDictionary dictionary];
- [sendParm setValue:@"cancelDownloadCourseware" forKey:@"api"];
- [sendParm setValue:content forKey:@"content"];
- [self postMessage:sendParm];
- }
- else if ([[parm ks_stringValueForKey:@"api"] isEqualToString:@"cloudLoading"]) { // loading
- NSDictionary *content = [parm ks_dictionaryValueForKey:@"content"];
- BOOL showLoading = [content ks_boolValueForKey:@"show"];
- if (showLoading) {
- [self showCustomLoading];
- }
- else {
- [self removeCustomLoadingView];
- }
- }
- else if ([[parm ks_stringValueForKey:@"api"] isEqualToString:@"openOutLink"]) {
- NSDictionary *content = [parm ks_dictionaryValueForKey:@"content"];
- NSString *url = [content ks_stringValueForKey:@"url"];
- [self openOutLink:url];
- }
- }
- - (void)openOutLink:(NSString *)url {
- // 外部浏览器打开
- [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[url getUrlEndcodeString]] options: @{} completionHandler: nil];
- }
- - (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 = CLIENT_THEMECOLOR;
- documentPickerVC.currentType = KSDOCUMENT_TYPE_DOWNLOADFILE;
- // 设置代理
- documentPickerVC.delegate = self;
- // 设置模态弹出方式
- documentPickerVC.modalPresentationStyle = UIModalPresentationFormSheet;
- [self.navigationController presentViewController:documentPickerVC animated:YES completion:nil];
- }
- - (void)downloadWithParm:(NSDictionary *)parm {
- MJWeakSelf;
- [COURSEWARE_MANAGER downloadCourseWithParm:parm callback:^(NSDictionary * _Nonnull sendParm) {
- [weakSelf postMessage:sendParm];
- }];
- }
- - (void)removeLoadHud {
- [LOADING_MANAGER removeCustomLoading];
- }
- - (void)videCropImage:(UIImage *)cover content:(NSDictionary *)content {
- NSData *imgData = [UIImage turnsImaegDataByImage:cover];
- NSString *fileName = @"videoCoverImage";
-
- [LOADING_MANAGER showCancelCustomLoading:@"上传中..." cancel:^{
- [UPLOAD_MANAGER cancelUploadCallback:^{
- [self removeLoadHud];
- }];
- }];
- [UPLOAD_MANAGER configWithfilePath:@"/user/"];
- [UPLOAD_MANAGER uploadFile:imgData fileName:fileName fileSuffix:[UIImage typeForImageData:imgData] 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 removeCustomLoading];
- NSString *fileUrl = [fileUrlArray lastObject];
- NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithDictionary:content];
- [dic setValue:fileUrl forKey:@"videoCover"];
- NSMutableDictionary *sendParm = [NSMutableDictionary dictionary];
- [sendParm setValue:@"videoCrop" forKey:@"api"];
- [sendParm setValue:dic forKey:@"content"];
- [self postMessage:sendParm];
- } faliure:^(NSError * _Nullable error, NSString * _Nullable descMessaeg) {
- [LOADING_MANAGER removeCustomLoading];
- }];
- }
- - (void)downFile:(NSString *)fileUrl {
- [LOADING_MANAGER showCustomLoading:@"文件下载中..."];
- [KSNetworkingManager downloadFileRequestWithFileUrl:fileUrl progress:^(int64_t bytesRead, int64_t totalBytes) {
-
- } success:^(NSURL * _Nonnull fileUrl) {
- [LOADING_MANAGER removeCustomLoading];
- [self saveFileWithUrl:fileUrl];
- } faliure:^(NSError * _Nonnull error) {
- [LOADING_MANAGER removeCustomLoading];
- [LOADING_MANAGER MBShowAUTOHidingInWindow:@"下载失败"];
- }];
- }
- - (void)saveFileWithUrl:(NSURL *)fileUrl {
- if ([fileUrl.absoluteString hasSuffix:@".mp4"]) { // 视频
- [RecordCheckManager checkPhotoLibraryPremissionAvaiableCallback:^(PREMISSIONTYPE type) {
- if (type == PREMISSIONTYPE_YES) {
- [self saveVideo:fileUrl];
- }
- else {
- [self showAlertWithMessage:@"请开启相册访问权限" type:CHECKDEVICETYPE_CAMREA];
- }
- }];
- }
- else { // 音频
- [self saveFileToPhone:fileUrl];
- }
- }
- - (void)saveVideo:(NSURL *)fileUrl {
- [LOADING_MANAGER showCustomLoading:@"视频保存中..."];
- [[TZImageManager manager] saveVideoWithUrl:fileUrl completion:^(PHAsset *asset, NSError *error) {
- if (!error) {
- dispatch_main_async_safe(^{
- [LOADING_MANAGER removeCustomLoading];
- [LOADING_MANAGER MBShowAUTOHidingInWindow:@"已保存到相册"];
- });
- }
- else {
- dispatch_main_async_safe(^{
- [LOADING_MANAGER removeCustomLoading];
- [LOADING_MANAGER MBShowAUTOHidingInWindow:@"保存视频错误"];
- });
- }
- }];
- }
- - (void)saveFileToPhone:(NSURL *)fileUrl {
- // 判断是否是音频
- AVAsset * asset =[AVAsset assetWithURL:fileUrl];
- KSDOCUMENT_TYPE currentType = KSDOCUMENT_TYPE_DOWNLOADFILE;
- if ([asset tracksWithMediaType:AVMediaTypeAudio].count > 0) {
- currentType = KSDOCUMENT_TYPE_DOWNLOADAUDIO;
- }
-
- self.isDownloadFile = YES;
- self.downloadFileUrl = fileUrl;
- KSDocumentViewController *documentPicker = [[KSDocumentViewController alloc] initWithURL:fileUrl inMode:UIDocumentPickerModeExportToService];
- documentPicker.buttonColor = CLIENT_THEMECOLOR;
- documentPicker.currentType = currentType;
- documentPicker.delegate = self;
- documentPicker.modalPresentationStyle = UIModalPresentationFormSheet;
- [self presentViewController:documentPicker animated:YES completion:nil];
- }
- - (void)chooseFileWithType:(NSString *)typeStr maxNumber:(NSInteger)maxCount bucket:(NSString *)bucket {
- if ([typeStr isEqualToString:@"img"]) { // 选择图片上传
- if (maxCount > 9) {
- maxCount = 9;
- }
- [self chooseMediaWithType:MEDIATYPE_PHOTO maxCount:maxCount bucket:bucket];
- }
- else if ([typeStr isEqualToString:@"video"]) {
- [self chooseMediaWithType:MEDIATYPE_VIDEO maxCount:1 bucket:bucket];
- }
- else if ([typeStr isEqualToString:@"file"]) {
- [self chooseDocumentWithType:CHOOSETYPE_ALL bucket:bucket];
- }
- else if ([typeStr isEqualToString:@"midi"]) {
- [self chooseDocumentWithType:CHOOSETYPE_MIDI bucket:bucket];
- }
- else if ([typeStr isEqualToString:@"mp3"]) {
- [self chooseDocumentWithType:CHOOSETYPE_MP3 bucket:bucket];
- }
- else if (([typeStr isEqualToString:@"xml"] || [typeStr isEqualToString:@"musicxml"])) {
- [self chooseDocumentWithType:CHOOSETYPE_XML bucket:bucket];
- }
- }
- - (void)chooseDocumentWithType:(CHOOSETYPE)fileTyle bucket:(NSString *)bucket {
- self.bucketName = bucket;
- 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 = CLIENT_THEMECOLOR;
- documentPickerViewController.currentType = KSDOCUMENT_TYPE_UPLOAD;
- documentPickerViewController.delegate = self;
- documentPickerViewController.modalPresentationStyle = UIModalPresentationFullScreen;
- [self presentViewController:documentPickerViewController animated:YES completion:nil];
- }
- - (void)chooseMediaWithType:(MEDIATYPE)type maxCount:(NSInteger)maxCount bucket:(NSString *)bucketName {
- self.mediaManager = [[KSMediaManager alloc] init];
- self.mediaManager.mediaType = type;
- self.mediaManager.maxPhotoNumber = maxCount;
- self.mediaManager.baseCtrl = self;
- self.mediaManager.needCropImage = NO;
- self.mediaManager.videoMaxDuration = 40 * 60;
- MJWeakSelf;
- [self.mediaManager noAlertCallback:^(NSString * _Nullable videoUrl, NSMutableArray * _Nullable imageArray, NSMutableArray * _Nullable imageAsset) {
-
- if (type == MEDIATYPE_PHOTO) {
- [weakSelf uploadImageArray:imageArray bucket:bucketName];
- }
- else {
- NSLog(@"%@", videoUrl);
- // 上传视频
- [weakSelf uploadVideoWithUrl:videoUrl bucket:bucketName];
- }
-
- }];
- [self.mediaManager pushImagePickerController];
- }
- - (void)savePicCallback:(NSString *)uuid isSuccess:(BOOL)isSuccess {
- NSString *status = isSuccess ? @"success" : @"fail";
- NSMutableDictionary *parm = [NSMutableDictionary dictionary];
- [parm setValue:@"savePicture" forKey:@"api"];
- NSMutableDictionary *content = [NSMutableDictionary dictionary];
- [content setValue:status forKey:@"status"];
- [content setValue:uuid forKey:@"uuid"];
- [parm setValue:content forKey:@"content"];
- [self postMessage:parm];
- }
- - (void)sendAddressAction:(AddressListModel *)model {
- NSMutableDictionary *sendParm = [NSMutableDictionary dictionary];
- [sendParm setValue:@"getAddress" forKey:@"api"];
- NSMutableDictionary *content = [NSMutableDictionary dictionary];
- [content setValue:model.internalBaseClassIdentifier forKey:@"id"];
- [content setValue:model.detailAddress forKey:@"detailAddress"];
- [content setValue:model.city forKey:@"city"];
- [content setValue:model.region forKey:@"region"];
- [content setValue:model.province forKey:@"province"];
- [content setValue:model.name forKey:@"name"];
- [content setValue:model.phoneNumber forKey:@"phoneNumber"];
- [content setValue:model.postCode forKey:@"postCode"];
- [sendParm setValue:content forKey:@"content"];
- [self postMessage:sendParm];
- }
- - (UIImage *)imageWithBase64String:(NSString *)base64String {
- NSURL *URL = [NSURL URLWithString:base64String];
- NSData *imageData = [NSData dataWithContentsOfURL:URL];
- UIImage *image = [UIImage imageWithData:imageData scale:2];
- return image;
- }
- - (void)shareFunctionWithParm:(NSDictionary *)parm {
-
- NSDictionary *content = [parm ks_dictionaryValueForKey:@"content"];
- NSString *typeString = [content ks_stringValueForKey:@"type"];
- KSSHARETYPE shareType = [typeString isEqualToString:@"image"] ? KSSHARETYPE_IMAGE : KSSHARETYPE_VODEO;
- NSString *shareTitle = [content ks_stringValueForKey:@"title"];
- NSString *descMessage = [content ks_stringValueForKey:@"desc"];
- NSString *videoUrl = [content ks_stringValueForKey:@"video"];
- NSString *saveLinkUrl = [content ks_stringValueForKey:@"url"];
- NSString *imgStr = [content ks_stringValueForKey:@"image"];
- UIImage *shareImage = [self imageWithBase64String:imgStr];
- NSArray *buttonArray = [content ks_arrayValueForKey:@"button"];
- BOOL containCopyButton = NO;
- for (NSString *nameString in buttonArray) {
- if ([nameString isEqualToString:@"copy"]) {
- containCopyButton = YES;
- break;
- }
- }
-
- MJWeakSelf;
- self.shareManager = [KSUMShareManager shareInstanceShowWithImage:shareImage showSaveLink:containCopyButton saveLinkUrl:saveLinkUrl url:videoUrl shareTitle:shareTitle descMessage:descMessage shareType:shareType showInView:self callback:^(BOOL isSuccess, NSString * _Nonnull descMessage) {
- NSMutableDictionary *responParm = [NSMutableDictionary dictionary];
- [responParm setValue:[parm ks_stringValueForKey:@"api"] forKey:@"api"];
- NSMutableDictionary *content = [NSMutableDictionary dictionary];
- [content setValue:[content ks_stringValueForKey:@"UUID"] forKey:@"content"];
- [content setValue:descMessage forKey:@"message"];
- BOOL status = isSuccess;
- [content setValue:[NSNumber numberWithBool:status] forKey:@"status"];
- [responParm setValue:content forKey:@"content"];
- [weakSelf postMessage:responParm];
- }];
- }
- - (KSSHARETYPE)getTypeWithTypeString:(NSString *)typeString {
- if ([typeString isEqualToString:@"image"]) { // 图片
- return KSSHARETYPE_IMAGE;
- }
- else if ([typeString isEqualToString:@"link"]) { // 链接
- return KSSHARETYPE_URL;
- }
- else {
- return KSSHARETYPE_VODEO;
- }
- }
- - (void)shareToWeChat:(NSDictionary *)parm {
-
- NSDictionary *content = [parm ks_dictionaryValueForKey:@"content"];
- if ([[content ks_stringValueForKey:@"shareType"] isEqualToString:@"wechat"]) {
- NSString *typeString = [content ks_stringValueForKey:@"type"];
- KSSHARETYPE shareType = [self getTypeWithTypeString:typeString];
- NSString *shareTitle = [content ks_stringValueForKey:@"title"];
- NSString *descMessage = [content ks_stringValueForKey:@"desc"];
- NSString *url = [content ks_stringValueForKey:@"video"];
- if (shareType == KSSHARETYPE_URL) {
- url = [content ks_stringValueForKey:@"url"];
- }
- NSString *imgStr = [content ks_stringValueForKey:@"image"];
- UIImage *shareImage = [self imageWithBase64String:imgStr];
- NSString *thumImage = [content ks_stringValueForKey:@"thumb"];
-
- MJWeakSelf;
- self.shareManager = [KSUMShareManager shareInstanceToWechatWithImage:shareImage url:url shareTitle:shareTitle descMessage:descMessage shareType:shareType thumImage:thumImage callback:^(BOOL isSuccess, NSString * _Nonnull descMessage) {
- NSMutableDictionary *responParm = [NSMutableDictionary dictionary];
- [responParm setValue:[parm ks_stringValueForKey:@"api"] forKey:@"api"];
- NSMutableDictionary *content = [NSMutableDictionary dictionary];
- [content setValue:[content ks_stringValueForKey:@"UUID"] forKey:@"content"];
- [content setValue:descMessage forKey:@"message"];
- BOOL status = isSuccess;
- [content setValue:[NSNumber numberWithBool:status] forKey:@"status"];
- [responParm setValue:content forKey:@"content"];
- [weakSelf postMessage:responParm];
- }];
- }
- else if ([[content ks_stringValueForKey:@"shareType"] isEqualToString:@"wechat_circle"]) { // 微信朋友圈
- NSString *typeString = [content ks_stringValueForKey:@"type"];
- KSSHARETYPE shareType = [self getTypeWithTypeString:typeString];
- NSString *shareTitle = [content ks_stringValueForKey:@"title"];
- NSString *descMessage = [content ks_stringValueForKey:@"desc"];
- NSString *url = [content ks_stringValueForKey:@"video"];
- if (shareType == KSSHARETYPE_URL) {
- url = [content ks_stringValueForKey:@"url"];
- }
- NSString *imgStr = [content ks_stringValueForKey:@"image"];
- UIImage *shareImage = [self imageWithBase64String:imgStr];
- NSString *thumImage = [content ks_stringValueForKey:@"thumb"];
- MJWeakSelf;
- self.shareManager = [KSUMShareManager shareInstanceToWechatCircleWithImage:shareImage url:url shareTitle:shareTitle descMessage:descMessage shareType:shareType thumImage:thumImage callback:^(BOOL isSuccess, NSString * _Nonnull descMessage) {
- NSMutableDictionary *responParm = [NSMutableDictionary dictionary];
- [responParm setValue:[parm ks_stringValueForKey:@"api"] forKey:@"api"];
- NSMutableDictionary *content = [NSMutableDictionary dictionary];
- [content setValue:[content ks_stringValueForKey:@"UUID"] forKey:@"content"];
- [content setValue:descMessage forKey:@"message"];
- BOOL status = isSuccess;
- [content setValue:[NSNumber numberWithBool:status] forKey:@"status"];
- [responParm setValue:content forKey:@"content"];
- [weakSelf postMessage:responParm];
- }];
- }
- }
- - (void)showAlertWithMessage:(NSString *)message type:(CHECKDEVICETYPE)deviceType {
- [KSPremissionAlert shareInstanceDisplayImage:deviceType message:message showInView:self.view cancel:^{
-
- } confirm:^{
- [self openSettingView];
- }];
-
- }
- - (void)openSettingView {
- [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString] options:@{} completionHandler:nil];
- }
- - (void)displaySource:(NSURL *)localUrl {
- KSLocalWebViewController *ctrl = [[KSLocalWebViewController alloc] init];
- ctrl.headTitle = @"协议文件";
- ctrl.sourceData = [NSData dataWithContentsOfURL:localUrl];
- ctrl.fileUrl = localUrl;
- [self.navigationController pushViewController:ctrl animated:YES];
- }
- - (void)postMessage:(NSDictionary *)parm {
- NSLog(@"------ parm %@", [parm mj_JSONString]);
- if (_myWebView) {
- dispatch_async(dispatch_get_main_queue(), ^{
- NSString *jsString = [parm mj_JSONString];
- [self.myWebView evaluateJavaScript:[NSString stringWithFormat:@"postMessage(%@,'*')", jsString] completionHandler:nil];
- });
- }
- }
- // 刷新
- - (void)refreshUrl:(NSString *)refreshUrl {
-
- NSString *sepectString = [refreshUrl containsString:@"?"] ? @"&" : @"?";
- NSString *tokenStr = UserDefault(TokenKey);
- if (![NSString isEmptyString:tokenStr]) {
- NSString *token = [[NSString stringWithFormat:@"Authorization=%@ %@", UserDefault(Token_type), tokenStr] stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
- refreshUrl = [NSString stringWithFormat:@"%@%@%@",refreshUrl, sepectString, token];
- }
- NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:refreshUrl] cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:60.0f];
- [self.myWebView loadRequest:request];
- }
- // 返回登录页面
- - (void)backLoginView {
-
- NSString *webUrl = [self.url copy];
- if ([webUrl containsString:@"Authorization="]) {
- NSRange range = [webUrl rangeOfString:@"Authorization="];
- if (range.location != NSNotFound) {
- webUrl = [webUrl substringToIndex:range.location-1];
- }
- }
-
- // 获取次数
- NSString *failCount = UserDefault(@"WEB_FAILCOUNT");
- if ([NSString isEmptyString:failCount]) {
- failCount = @"1";
- UserDefaultSetObjectForKey(failCount, @"WEB_FAILCOUNT");
- UserDefaultSetObjectForKey(webUrl, WEB_URL);
- }
- else if (failCount.integerValue == 1) {
-
- NSString *preUrl = UserDefaultObjectForKey(FAIL_WEB_URL);
- if (![webUrl isEqualToString:preUrl]) { // 如果打开和之前失败不相同重新统计数据
- UserDefaultSetObjectForKey(@"1", @"WEB_FAILCOUNT");
- UserDefaultSetObjectForKey(webUrl, WEB_URL);
- }
- else {
- UserDefaultRemoveObjectForKey(@"WEB_FAILCOUNT");
- }
- }
- else {
- UserDefaultRemoveObjectForKey(@"WEB_FAILCOUNT");
- }
- // 当前失败的H5地址
- UserDefaultSetObjectForKey(webUrl, FAIL_WEB_URL);
-
- // 退出登录
- [APPLOGIN_MANAGER logoutActionWithMsg:@""];
- }
-
- #pragma mark ----- WKWebView delegate
- // 1 在发送请求之前,决定是否跳转
- - (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler {
- NSLog(@"1-------在发送请求之前,决定是否跳转 -->%@",navigationAction.request);
- NSURL *url = navigationAction.request.URL;
- NSString *scheme = [url scheme];
- UIApplication *app = [UIApplication sharedApplication];
- NSString *urlString = url.absoluteString;
- if (![urlString containsString:@"colexiu.com"] && ![urlString containsString:WEBHOST]) { // 外部链接
- self.isOutLink = YES;
- }
- else {
- self.isOutLink = NO;
- }
- // 打电话
- if ([scheme isEqualToString:@"tel"]) {
- if ([app canOpenURL:url]) {
- [app openURL:url];
- // 一定要加上这句,否则会打开新页面
- decisionHandler(WKNavigationActionPolicyCancel);
- return;
- }
- }
-
- decisionHandler(WKNavigationActionPolicyAllow);
- }
- // 2 页面开始加载时调用
- - (void)webView:(WKWebView *)webView didStartProvisionalNavigation:(WKNavigation *)navigation {
- NSLog(@"2-------页面开始加载时调用");
- }
- // 3 在收到响应后,决定是否跳转
- - (void)webView:(WKWebView *)webView decidePolicyForNavigationResponse:(WKNavigationResponse *)navigationResponse decisionHandler:(void (^)(WKNavigationResponsePolicy))decisionHandler {
- /// 在收到服务器的响应头,根据response相关信息,决定是否跳转。decisionHandler必须调用,来决定是否跳转,参数WKNavigationActionPolicyCancel取消跳转,WKNavigationActionPolicyAllow允许跳转
- NSLog(@"3-------在收到响应后,决定是否跳转");
- decisionHandler(WKNavigationResponsePolicyAllow);
- }
- // 4 当内容开始返回时调用
- - (void)webView:(WKWebView *)webView didCommitNavigation:(WKNavigation *)navigation {
- NSLog(@"4-------当内容开始返回时调用");
- }
- // 5 页面加载完成之后调用
- - (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation {
- NSLog(@"5-------页面加载完成之后调用");
- if (_hasModify == NO) {
- [self configLocalStorage];
- }
- }
- // 调用js方法
- - (void)postMessageJS:(NSDictionary *)jsDict {
- NSString *jsString = [jsDict mj_JSONString];
- [self.myWebView evaluateJavaScript:[NSString stringWithFormat:@"sendMessage(%@)", jsString] completionHandler:nil];
- }
- // 6 页面加载失败时调用
- - (void)webView:(WKWebView *)webView didFailProvisionalNavigation:(WKNavigation *)navigation withError:(NSError *)error {
- NSLog(@"6-------页面加载失败时调用");
- [self showErrorView];
- }
- // 接收到服务器跳转请求之后调用
- - (void)webView:(WKWebView *)webView didReceiveServerRedirectForProvisionalNavigation:(WKNavigation *)navigation {
- NSLog(@"-------接收到服务器跳转请求之后调用");
- }
- // 数据加载发生错误时调用
- - (void)webView:(WKWebView *)webView didFailNavigation:(null_unspecified WKNavigation *)navigation withError:(NSError *)error {
- NSLog(@"----数据加载发生错误时调用");
- // 错误上报
- if (error) {
- if (error.code == -999) {
- NSLog(@"-- error desc - %@", error.description);
- NSMutableDictionary *parm = [NSMutableDictionary dictionary];
- [parm setValue:UserDefault(UIDKey) forKey:@"userId"];
- [parm setValue:@"KSBaseWKWebViewController" forKey:@"Location"];
- [parm setValue:webView.URL.absoluteString forKey:@"url"];
- [parm setValue:@(error.code) forKey:@"errorCode"];
- [parm setValue:error.description forKey:@"errorDesc"];
- [parm setValue:[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"] forKey:@"version"];
-
- NSString *content = [parm mj_JSONString];
- NSMutableDictionary *uploadParm = [KSLogManager generateLogMessageWithContent:content type:@"ERROR"];
- NSMutableArray *uploadArray = [NSMutableArray arrayWithObject:uploadParm];
- [KSNetworkingManager sysExceptionLogUpdate:KS_POST token:UserDefault(TokenKey) logArray:uploadArray success:^(NSDictionary * _Nonnull dic) {
- if ([dic ks_integerValueForKey:@"code"] == 200) {
-
- }
- } faliure:^(NSError * _Nonnull error) {
-
- }];
- }
- }
- }
- - (void)webView:(WKWebView *)webView didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition, NSURLCredential *_Nullable))completionHandler
- {
- dispatch_queue_t queue = dispatch_queue_create("webViewChallengeQueue", NULL);
- dispatch_async(queue, ^{
- if (SSL_AUTH) {
- NSURLSessionAuthChallengeDisposition disposition = NSURLSessionAuthChallengePerformDefaultHandling;
- NSURLCredential *customCredential = nil;
-
- if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]) {
- // 默认信任
- customCredential = [NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust];
- disposition = NSURLSessionAuthChallengeUseCredential;
- }
- else if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodClientCertificate]) {
- // client authentication
- SecIdentityRef identity = NULL;
- SecTrustRef trust = NULL;
- if ([AuthChallengeManager extractIdentity:&identity andTrust:&trust filePath:CERT_PATH]) {
- SecCertificateRef certificate = NULL;
- SecIdentityCopyCertificate(identity, &certificate);
- const void*certs[] = {certificate};
- CFArrayRef certArray =CFArrayCreate(kCFAllocatorDefault, certs,1,NULL);
- customCredential =[NSURLCredential credentialWithIdentity:identity certificates:(__bridge NSArray*)certArray persistence:NSURLCredentialPersistencePermanent];
- disposition = NSURLSessionAuthChallengeUseCredential;
- // 释放 CFArrayRef 和 SecCertificateRef
- CFRelease(certArray);
- CFRelease(certificate);
- }
- }
-
- if (completionHandler) {
- completionHandler(disposition, customCredential);
- }
- }
- else {
- if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]) {
- if (challenge.previousFailureCount == 0) {
- NSURLCredential *credential = [NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust];
- completionHandler(NSURLSessionAuthChallengeUseCredential, credential);
- } else {
- completionHandler(NSURLSessionAuthChallengeCancelAuthenticationChallenge, nil);
- }
- }
- else {
- completionHandler(NSURLSessionAuthChallengeCancelAuthenticationChallenge, nil);
- }
- }
- });
- }
- //当因为某些问题,导致webView进程终止时触发
- - (void)webViewWebContentProcessDidTerminate:(WKWebView *)webView {
- NSLog(@"%s", __func__);
- if (self.navigationController.visibleViewController == self) {
- [webView reload];
- }
- else {
- self.needReload = YES;
- }
- }
- /**
- * web界面中有弹出警告框时调用
- *
- * @param webView 实现该代理的webview
- * @param message 警告框中的内容
- * @param completionHandler 警告框消失调用
- */
- - (void)webView:(WKWebView *)webView runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(void))completionHandler {
- NSLog(@"-------web界面中有弹出警告框时调用");
- NSLog(@"%@",message);
- UIAlertController *alertController = [UIAlertController alertControllerWithTitle:message
- message:nil
- preferredStyle:UIAlertControllerStyleAlert];
- [alertController addAction:[UIAlertAction actionWithTitle:@"确定"
- style:UIAlertActionStyleCancel
- handler:^(UIAlertAction *action) {
- completionHandler();
- }]];
-
- [self presentViewController:alertController animated:YES completion:nil];
- }
- // 取消和确认的按钮
- - (void)webView:(WKWebView *)webView runJavaScriptConfirmPanelWithMessage:(NSString *)message initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(BOOL))completionHandler {
- // js 里面的alert实现,如果不实现,网页的alert函数无效 ,
- UIAlertController *alertController = [UIAlertController alertControllerWithTitle:message
- message:nil
- preferredStyle:UIAlertControllerStyleAlert];
- [alertController addAction:[UIAlertAction actionWithTitle:@"确定"
- style:UIAlertActionStyleDefault
- handler:^(UIAlertAction *action) {
- completionHandler(YES);
- }]];
- [alertController addAction:[UIAlertAction actionWithTitle:@"取消"
- style:UIAlertActionStyleCancel
- handler:^(UIAlertAction *action){
- completionHandler(NO);
- }]];
-
- [self presentViewController:alertController animated:YES completion:^{}];
-
- }
- #pragma mark - KVO回馈
- -(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context{
- if ([keyPath isEqualToString:@"estimatedProgress"]) {
- self.progressLayer.opacity = 1;
- if ([change[@"new"] floatValue] <[change[@"old"] floatValue]) {
- return;
- }
- self.progressLayer.frame = CGRectMake(0, 0, kScreenWidth*[change[@"new"] floatValue], 3);
- if ([change[@"new"]floatValue] == 1.0) {
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- self.progressLayer.opacity = 0;
- self.progressLayer.frame = CGRectMake(0, 0, 0, 3);
- });
- }
- }
- }
- /*
- #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.
- }
- */
- - (void)configLocalStorage {
- _hasModify = YES;
- if (![NSString isEmptyString:UserDefault(TokenKey)]) {
- NSString *jsString = [NSString stringWithFormat:@"localStorage.setItem('Authorization', '%@ %@')",UserDefault(Token_type), UserDefault(TokenKey)];
- [self.myWebView evaluateJavaScript:jsString completionHandler:nil];
- }
- }
- - (void)setupProgress {
- UIView *progress = [[UIView alloc]init];
- progress.frame = CGRectMake(0, 0, kScreenWidth, 3);
- progress.backgroundColor = [UIColor clearColor];
- [self.view addSubview:progress];
-
- CALayer *layer = [CALayer layer];
- layer.frame = CGRectMake(0, 0, 0, 3);
- layer.backgroundColor = CLIENT_THEMECOLOR.CGColor;
- [progress.layer addSublayer:layer];
- self.progressLayer = layer;
- }
- + (WKProcessPool*)singleWkProcessPool {
- static WKProcessPool *sharedPool;
- static dispatch_once_t onceToken;
- dispatch_once(&onceToken, ^{
- sharedPool = [[WKProcessPool alloc] init];
- });
- return sharedPool;
- }
- - (NSDictionary *)convertJsonStringToNSDictionary:(NSString *)jsonString {
- if (jsonString == nil) {
- return nil;
- }
- NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
- NSError *error;
- NSDictionary *json = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&error];
- if (error) {
- NSLog(@"jsonString解析失败:%@", error);
- return nil;
- }
- return json;
- }
- - (void)dealloc {
- NSLog(@"webView dealloc -----");
- [[_myWebView configuration].userContentController removeScriptMessageHandlerForName:SCRIPT_NAME];
- [_myWebView removeObserver:self forKeyPath:@"estimatedProgress"];
- [_myWebView removeObserver:self forKeyPath:@"title"];
- [_myWebView loadHTMLString:@"" baseURL:nil];
- [_myWebView removeFromSuperview];
- _myWebView = nil;
- [self clearWebCache];
- // [[NSURLCache sharedURLCache] removeAllCachedResponses];
- // [[NSURLCache sharedURLCache] setDiskCapacity:0];
- [[NSURLCache sharedURLCache] setMemoryCapacity:0];
- [[NSNotificationCenter defaultCenter] removeObserver:self];
- }
- - (void)clearWebCache {
- NSSet *websiteDataTypes = [NSSet setWithArray:@[
- WKWebsiteDataTypeMemoryCache,
- ]];
- NSDate *dateFrom = [NSDate dateWithTimeIntervalSince1970:0];
- [[WKWebsiteDataStore defaultDataStore] removeDataOfTypes:websiteDataTypes
- modifiedSince:dateFrom
- completionHandler:^{
- NSLog(@"Caches cleared");
- }];
- }
- - (NSString *)getSaveSpeedPath {
- // 在Documents目录下创建一个名为AudioSpeedFile的文件夹
- NSString *path = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)lastObject] stringByAppendingPathComponent:@"AudioSpeedFile"];
- NSLog(@"%@",path);
-
- NSFileManager *fileManager = [NSFileManager defaultManager];
- BOOL isDir = FALSE;
- BOOL isDirExist = [fileManager fileExistsAtPath:path isDirectory:&isDir];
- if(!(isDirExist && isDir)) {
- BOOL bCreateDir = [fileManager createDirectoryAtPath:path withIntermediateDirectories:YES attributes:nil error:nil];
- if(!bCreateDir){
- NSLog(@"创建文件夹失败!");
- }
- NSLog(@"创建文件夹成功,文件路径%@",path);
- }
-
- path = [path stringByAppendingPathComponent:@"songSpeed.plist"];
- NSLog(@"file path:%@",path);
- 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.attributedText = [self getAttrStringWithText:@"正在上传视频文件..."];
- _HUD.contentColor = [UIColor whiteColor];
- _HUD.bezelView.style = MBProgressHUDBackgroundStyleSolidColor;
- _HUD.bezelView.backgroundColor = HexRGBAlpha(0x000000, 0.8);
- _HUD.removeFromSuperViewOnHide = YES;
-
- }else{
- _HUD.progress = 0;
- [keyWindow addSubview:_HUD];
- [_HUD showAnimated:YES];
- }
- }else{
- [_HUD hideAnimated:YES];
- }
- }
- - (NSMutableAttributedString *)getAttrStringWithText:(NSString *)text {
- if (![NSString isEmptyString:text]) {
- NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
- [paragraphStyle setLineSpacing:6];//调整行间距
- NSMutableAttributedString *attr = [[NSMutableAttributedString alloc] initWithString:text attributes:@{NSParagraphStyleAttributeName:paragraphStyle,NSFontAttributeName:[UIFont systemFontOfSize:16],NSForegroundColorAttributeName:HexRGB(0xffffff)}];
- return attr;
- }
- else {
- return [[NSMutableAttributedString alloc] initWithString:@""];
- }
- }
- - (void)uploadImageArray:(NSMutableArray *)imageArray bucket:(NSString *)bucket {
- [LOADING_MANAGER showHUD];
- NSMutableArray *imageDataArray = [NSMutableArray array];
- for (UIImage *image in imageArray) {
- NSData *imgData = [UIImage turnsImaegDataByImage:image];
- [imageDataArray addObject:imgData];
- }
- [UPLOAD_MANAGER configWithfilePath:@"/user/"];
- [UPLOAD_MANAGER mutilUploadImage:imageDataArray fileName:@"complainImg" successCallback:^(NSMutableArray * _Nonnull fileUrlArray) {
- [LOADING_MANAGER removeHUD];
- NSMutableArray *urlArray = [NSMutableArray array];
- for (NSString *url in fileUrlArray) {
- [urlArray addObject:url];
- }
- NSString *attachments = [urlArray componentsJoinedByString:@","];
- if (self.chooseFileParm) { // 回调
- [self.chooseFileParm setValue:attachments 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];
- }];
- }
- #pragma mark --- 上传视频文件
- - (void)uploadVideoWithUrl:(NSString *)videoUrl bucket:(NSString *)bucket {
- // 取出视频第一帧
- UIImage *previewImage = [self firstFrameWithVideoURL:[NSURL fileURLWithPath:videoUrl] size:CGSizeMake(1280, 720)];
- __block NSString *imageUrl = @"";
- if (previewImage) { // 如果有第一帧
- NSData *imgData = [UIImage turnsImaegDataByImage:previewImage];
- NSString *fileName = @"videoPreviewImg";
- [UPLOAD_MANAGER configWithfilePath:@"/user/"];
- [UPLOAD_MANAGER uploadImage:imgData fileName:fileName successCallback:^(NSMutableArray * _Nonnull fileUrlArray) {
- NSString *url = [fileUrlArray lastObject];
- imageUrl = url;
- [self submitUrlWith:imageUrl videoUrl:videoUrl];
- } faliure:^(NSError * _Nullable error, NSString *descMessaeg) {
- if (![NSString isEmptyString:descMessaeg]) {
- [LOADING_MANAGER MBShowAUTOHidingInWindow:descMessaeg];
- }
- [self fileChooseErrorCallback];
- }];
- }
- else {
- [self submitUrlWith:nil videoUrl:videoUrl];
- }
- }
- - (void)submitUrlWith:(NSString *)imgUrl videoUrl:(NSString *)videoUrl {
- // 上传视频
- [self hudTipWillShow:YES];
- NSURL *uploadFileUrl = [NSURL fileURLWithPath:videoUrl];
- NSData *fileData = [NSData dataWithContentsOfURL:uploadFileUrl];
- NSString *suffix = [NSString stringWithFormat:@".%@",[uploadFileUrl pathExtension]];
- [UPLOAD_MANAGER videoUpload:fileData fileName:@"video" fileSuffix:suffix progress:^(int64_t bytesWritten, int64_t totalBytes) {
- dispatch_main_async_safe(^{
- // 显示进度
- if (self.HUD) {
- self.HUD.progress = bytesWritten / totalBytes;// progress是回调进度
- }
- });
- } successCallback:^(NSMutableArray * _Nonnull fileUrlArray) {
- [self hudTipWillShow:NO];
- NSString *fileUrl = [fileUrlArray lastObject];
- [self videoUploadCallback:fileUrl firstFrameImg:imgUrl];
- } faliure:^(NSError * _Nullable error, NSString * _Nullable descMessaeg) {
- [self hudTipWillShow:NO];
- if (![NSString isEmptyString:descMessaeg]) {
- [LOADING_MANAGER MBShowAUTOHidingInWindow:descMessaeg];
- }
- [self videoUploadCallback:@"" firstFrameImg:@""];
- }];
- }
- - (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 {
- if (self.isDownloadFile) {
- self.isDownloadFile = NO;
- if (self.downloadParm) {
- [self downloadCallback:NO withParm:self.downloadParm];
- self.downloadParm = nil;
- }
- }
- else {
- [self fileChooseErrorCallback];
- }
- }
- - (void)documentPicker:(UIDocumentPickerViewController *)controller didPickDocumentsAtURLs:(NSArray <NSURL *>*)urls {
- if (self.isDownloadFile) {
- self.isDownloadFile = NO;
- [self downloadCallback:YES withParm:self.downloadParm];
- self.downloadParm = nil;
-
- NSURL *descUrl = [urls firstObject];
- NSString *desc = [descUrl absoluteString];
- KSDocumentViewController *ctrl = (KSDocumentViewController *)controller;
- if (ctrl.currentType == KSDOCUMENT_TYPE_DOWNLOADAUDIO) {
- KSAudioSaveAlert *alert = [KSAudioSaveAlert shareInstance];
- [alert configWithDesc:desc];
- [alert actionCallbackCancel:^{
-
- } copyCallback:^{
- [self copyAction:desc];
- } sure:^{
- [self openFileSource:descUrl];
- }];
- [alert showAlert];
- }
- else {
- NSLog(@"@------- %zd",[UserDefaultObjectForKey(TENANT_ID) integerValue]);
- 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];
- NSArray *array = [[url absoluteString] componentsSeparatedByString:@"/"];
- NSString *fileName = [array lastObject];
- fileName = [fileName stringByRemovingPercentEncoding];
-
- if (self.fileChooseType == CHOOSETYPE_XML) {
- if (![fileName hasSuffix:@".xml"]) {
- [LOADING_MANAGER MBShowAUTOHidingInWindow:@"请上传XML格式文件"];
- [self fileChooseErrorCallback];
- return;
- }
- }
- else if (self.fileChooseType == CHOOSETYPE_MIDI) {
- if (![fileName hasSuffix:@".mid"] || [fileName hasSuffix:@".midi"]) {
- [LOADING_MANAGER MBShowAUTOHidingInWindow:@"请上传mid格式文件"];
- [self fileChooseErrorCallback];
- return;
- }
- }
- else if (self.fileChooseType == CHOOSETYPE_MP3) {
- if (![fileName hasSuffix:@".mp3"]) {
- [LOADING_MANAGER MBShowAUTOHidingInWindow:@"请上传mp3格式文件"];
- [self fileChooseErrorCallback];
- return;
- }
- }
- else {
- if (![fileName hasSuffix:@".mp3"] && ![fileName hasSuffix:@".aac"]) {
- [LOADING_MANAGER MBShowAUTOHidingInWindow:@"暂不支持此格式!"];
- [self fileChooseErrorCallback];
- 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 {
- [LOADING_MANAGER MBShowAUTOHidingInWindow:@"写入文件错误!"];
- [self fileChooseErrorCallback];
- }
- }
- else {
- fileUrl = pathStr;
- }
- [self uploadFile:fileName fileUrl:pathStr];
-
- }];
- }
- else {
- [LOADING_MANAGER MBShowAUTOHidingInWindow:@"iCloud不可用!"];
- [self fileChooseErrorCallback];
- }
- }
- }
- - (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 {
- [self checkCaptured];
- }
- - (void)checkCaptured {
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- if ([self checkIsCaptured]) {
- [self didCapturedView];
- }
- });
- }
- - (BOOL)checkIsCaptured {
- if ([UIScreen mainScreen].isCaptured && [UIScreen screens].count < 2) {
- return YES;
- }
- return NO;
- }
- - (void)didCapturedView {
-
- NSMutableDictionary *sendParm = [NSMutableDictionary dictionary];
- [sendParm setValue:@"setVideoPlayer" forKey:@"api"];
- NSMutableDictionary *content = [NSMutableDictionary dictionary];
- [content setValue:@"pause" forKey:@"status"];
- [sendParm setValue:content forKey:@"content"];
- [self postMessage:sendParm];
- }
- - (KSWebLoadRefreshView *)errorView {
- if (!_errorView) {
- _errorView = [KSWebLoadRefreshView shareInstance];
- MJWeakSelf;
- [_errorView failViewActionCallback:^(BOOL isBack) {
- [weakSelf hideErrorView];
- if (isBack) {
- [weakSelf backAction];
- }
- else {
- [weakSelf loadRequest];
- }
- }];
- }
- return _errorView;
- }
- - (void)showErrorView {
- if (![self.view.subviews containsObject:self.errorView]) {
- [self.view addSubview:self.errorView];
- [self.errorView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.top.bottom.mas_equalTo(self.view);
- }];
- [self.view bringSubviewToFront:self.errorView];
- }
- }
- - (void)hideErrorView {
- if ([self.view.subviews containsObject:self.errorView]) {
- [self.errorView removeFromSuperview];
- }
- }
- #pragma mark ----- 小酷AI loading
- - (AccompanyLoadingView *)customLoading {
- if (!_customLoading) {
- _customLoading = [AccompanyLoadingView shareInstance];
- MJWeakSelf;
- [_customLoading loadingCallback:^{
- [weakSelf backAction];
- }];
- }
- return _customLoading;
- }
- - (void)showCustomLoading {
- if ([self.view.subviews containsObject:self.customLoading]) {
- return;
- }
- [self.view addSubview:self.customLoading];
- [self.customLoading mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.top.right.bottom.mas_equalTo(self.view);
- }];
- [self.view bringSubviewToFront:self.customLoading];
- [self.customLoading showLoading];
- }
- - (void)removeCustomLoadingView {
- [self.customLoading stopLoading];
- }
- /*
- #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
|