123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719 |
- #import "KSNewWhiteBoard.h"
- #import <KSToolLibrary/WeakWebViewScriptMessageDelegate.h>
- #import <WebKit/WebKit.h>
- #import "CustomNavViewController.h"
- #define MAXPHOTONUMBER (1)
- #define COLUMNNUMBER (3)
- #import "TZImageManager.h"
- #import <AssetsLibrary/AssetsLibrary.h>
- #import <Photos/Photos.h>
- #import "TZVideoPlayerController.h"
- #import "TZImagePickerController.h"
- #import <KSToolLibrary/UIImage+ResizeImage.h>
- #import <KSToolLibrary/UIImage+Color.h>
- #import "WhiteUtils.h"
- #import "WebViewBaseConfig.h"
- #define touchPy 10
- @interface KSNewWhiteBoard ()<WKUIDelegate,WKNavigationDelegate,WKScriptMessageHandler,UIImagePickerControllerDelegate,UINavigationControllerDelegate,TZImagePickerControllerDelegate,UIAlertViewDelegate,UIGestureRecognizerDelegate>
- {
- BOOL _isSelectOriginalPhoto;
- }
- @property (nonatomic, strong, nullable) WKWebView *myWebView;
- @property (nonatomic, assign) BOOL hasModify;
- @property (nonatomic, strong) UIImagePickerController *imagePickerVc;
- @property (nonatomic, strong) NSMutableArray *imageArray;
- @property (nonatomic, strong) NSMutableArray *imageAsset;
- @property (nonatomic, strong) UIImageView *chooseImage;
- @property (nonatomic, assign) CGPoint beginPoint;
- @property (nonatomic, weak) id<KSNewWhiteboardViewDelegate> delegate;
- @property (nonatomic, assign) BOOL isChoosePhoto;
- @property (nonatomic, assign) BOOL isLoadingSource;
- @property (nonatomic, assign) BOOL isJoinRoom;
- @end
- @implementation KSNewWhiteBoard
- - (instancetype)initWithDelegate:(id<KSNewWhiteboardViewDelegate>)delegate frame:(CGRect)frame {
- self = [super initWithFrame:frame];
- if (self) {
- self.delegate = delegate;
- }
- return self;
- }
- - (void)configView:(CGRect)frame {
- [self addSubview:self.myWebView];
- self.myWebView.userInteractionEnabled = NO;
- [self.myWebView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.top.bottom.mas_equalTo(self);
- }];
- [self addSubview:self.refreshButton];
- [self.refreshButton mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(self.myWebView.mas_left).offset(18);
- make.top.mas_equalTo(self.myWebView.mas_top).offset(10);
- make.width.mas_equalTo(81);
- make.height.mas_equalTo(21);
- }];
- }
- - (void)configUserAgent:(WKWebViewConfiguration *)config {
- NSString *oldUserAgent = config.applicationNameForUserAgent;
- NSString *newAgent = [NSString stringWithFormat:@"%@ %@ %@",oldUserAgent,AGENT_NAME,AGENT_DOMAIN];
- config.applicationNameForUserAgent = newAgent;
- }
- - (void)loadRequest {
- NSLog(@"---------- %@",self.url);
- NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:self.url] cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:60.0f];
- [self.myWebView loadRequest:request];
- }
- - (WKWebView *)myWebView {
- if (!_myWebView) {
- _myWebView = [[WKWebView alloc] initWithFrame:CGRectZero configuration:[self getwebConfig]];
- _myWebView.scrollView.bounces = NO;
- _myWebView.UIDelegate = self;
- _myWebView.navigationDelegate = self;
- #ifdef DEBUG
- if (@available(iOS 16.4, *)) {
- _myWebView.inspectable = YES;
- }
- #endif
- }
- return _myWebView;
- }
- - (WKWebViewConfiguration *)getwebConfig {
- WKWebViewConfiguration *config = [[WKWebViewConfiguration alloc] init];
- config.selectionGranularity = WKSelectionGranularityDynamic;
- config.allowsInlineMediaPlayback = YES;
- if (@available(iOS 10.0, *)) {
- config.mediaTypesRequiringUserActionForPlayback = NO;
- } else {
-
- config.requiresUserActionForMediaPlayback = NO;
- }
- config.processPool = [KSNewWhiteBoard singleWkProcessPool];
- config.websiteDataStore = [WKWebsiteDataStore defaultDataStore];
- [self configUserAgent:config];
-
- WeakWebViewScriptMessageDelegate *weakScriptMessageDelegate = [[WeakWebViewScriptMessageDelegate alloc] initWithDelegate:self];
-
- WKUserContentController * wkUController = [[WKUserContentController alloc] init];
- [wkUController addScriptMessageHandler:weakScriptMessageDelegate name:SCRIPT_NAME];
- config.userContentController = wkUController;
-
- WKPreferences *preferences = [WKPreferences new];
-
- preferences.javaScriptEnabled = YES;
-
- preferences.javaScriptCanOpenWindowsAutomatically = YES;
- config.preferences = preferences;
- return config;
- }
- + (WKProcessPool*)singleWkProcessPool {
- static WKProcessPool *sharedPool;
- static dispatch_once_t onceToken;
- dispatch_once(&onceToken, ^{
- sharedPool = [[WKProcessPool alloc] init];
- });
- return sharedPool;
- }
- - (void)postMessageJS:(NSDictionary *)jsDict {
- dispatch_async(dispatch_get_main_queue(), ^{
- NSString *jsString = [jsDict mj_JSONString];
- [self.myWebView evaluateJavaScript:[NSString stringWithFormat:@"postMessage(%@,'*')", jsString] completionHandler:nil];
- });
- }
- #pragma mark ----- WKWebView delegate
- - (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 ([scheme isEqualToString:@"tel"]) {
- if ([app canOpenURL:url]) {
- [app openURL:url];
-
- decisionHandler(WKNavigationActionPolicyCancel);
- return;
- }
- }
- decisionHandler(WKNavigationActionPolicyAllow);
- }
- - (void)webView:(WKWebView *)webView didStartProvisionalNavigation:(WKNavigation *)navigation {
- NSLog(@"2-------页面开始加载时调用");
- }
- - (void)webView:(WKWebView *)webView decidePolicyForNavigationResponse:(WKNavigationResponse *)navigationResponse decisionHandler:(void (^)(WKNavigationResponsePolicy))decisionHandler {
-
- NSLog(@"3-------在收到响应后,决定是否跳转");
- decisionHandler(WKNavigationResponsePolicyAllow);
- }
- - (void)webView:(WKWebView *)webView didCommitNavigation:(WKNavigation *)navigation {
- NSLog(@"4-------当内容开始返回时调用");
- }
- - (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation {
- NSLog(@"5-------页面加载完成之后调用");
- if (_hasModify == NO) {
- [self configLocalStorage];
- }
- }
- - (void)configLocalStorage {
- _hasModify = YES;
- NSString *jsString = [NSString stringWithFormat:@"localStorage.setItem('Authorization', '%@ %@')",UserDefault(Token_type), UserDefault(TokenKey)];
- [self.myWebView evaluateJavaScript:jsString completionHandler:nil];
- }
- - (void)webView:(WKWebView *)webView didFailProvisionalNavigation:(WKNavigation *)navigation withError:(NSError *)error {
- NSLog(@"6-------页面加载失败时调用");
- [LOADING_MANAGER MBShowAUTOHidingInWindow:@"网页加载失败!"];
- }
- - (void)webView:(WKWebView *)webView didReceiveServerRedirectForProvisionalNavigation:(WKNavigation *)navigation {
- NSLog(@"-------接收到服务器跳转请求之后调用");
- }
- - (void)webView:(WKWebView *)webView didFailNavigation:(null_unspecified WKNavigation *)navigation withError:(NSError *)error {
- NSLog(@"----数据加载发生错误时调用");
- [LOADING_MANAGER MBShowAUTOHidingInWindow:@"数据加载发生错误!"];
- }
- - (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]) {
-
- 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;
- }
- }
-
- 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);
- }
- }
- });
- }
- #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 {
- NSLog(@"----%@",parm);
- if ([[parm ks_stringValueForKey:@"api"] isEqualToString:@"whiteboardSelectPhoto"]) {
- self.isChoosePhoto = YES;
- [self pushImagePickerController];
- }
- else if ([[parm ks_stringValueForKey:@"api"] isEqualToString:@"whiteboardSelectMusicLibrary"]) {
- }
-
- else if ([[parm ks_stringValueForKey:@"api"] isEqualToString:@"whiteboardConnectStatus"]) {
- NSDictionary *valueDic = [parm ks_dictionaryValueForKey:@"content"];
- if ([[valueDic ks_stringValueForKey:@"status"] isEqualToString:@"success"]) {
- self.connectedSuccess = YES;
- }
- else {
- self.connectedSuccess = NO;
- [LOADING_MANAGER MBShowAUTOHidingInWindow:@"白板连接错误,请刷新一下"];
- }
- }
- }
- - (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(@"-white board-");
- [[_myWebView configuration].userContentController removeScriptMessageHandlerForName:SCRIPT_NAME];
- [_myWebView loadHTMLString:@"" baseURL:nil];
- [_myWebView removeFromSuperview];
- _myWebView = nil;
- [[NSURLCache sharedURLCache] removeAllCachedResponses];
- [[NSURLCache sharedURLCache] setDiskCapacity:0];
- [[NSURLCache sharedURLCache] setMemoryCapacity:0];
- [[NSNotificationCenter defaultCenter] removeObserver:self];
- }
- #pragma mark ------- 曲库下载或者相册选择
- - (void)uploadImage {
- UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:IS_IPAD ? UIAlertControllerStyleAlert : UIAlertControllerStyleActionSheet];
- [alertVC addAction:[UIAlertAction actionWithTitle:@"曲库选择" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
-
- [self chooseImageWithLibiary];
- }]];
- [alertVC addAction:[UIAlertAction actionWithTitle:@"从手机相册选择" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
-
- [self pushImagePickerController];
-
- }]];
- [alertVC addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
-
- }]];
- alertVC.modalPresentationStyle = UIModalPresentationFullScreen;
-
- [[self getViewController] presentViewController:alertVC animated:true completion:nil];
- }
- - (void)chooseImageWithLibiary {
-
- }
- #pragma mark - TZImagePickerController
- - (void)pushImagePickerController {
-
- TZImagePickerController *imagePickerVc = [[TZImagePickerController alloc] initWithMaxImagesCount:MAXPHOTONUMBER columnNumber:COLUMNNUMBER delegate:self];
-
- #pragma mark - 四类个性化设置,这些参数都可以不传,此时会走默认设置
- imagePickerVc.isSelectOriginalPhoto = NO;
-
-
- imagePickerVc.selectedAssets = self.imageAsset;
- imagePickerVc.allowTakePicture = YES;
-
-
-
- [imagePickerVc.navigationBar setBarTintColor:THEMECOLOR];
-
-
-
- imagePickerVc.allowPickingVideo = NO;
- imagePickerVc.allowPickingImage = YES;
- imagePickerVc.allowPickingOriginalPhoto = NO;
- imagePickerVc.allowCrop = NO;
- imagePickerVc.needCircleCrop = NO;
- imagePickerVc.showSelectBtn = YES;
- NSInteger left = 30;
- NSInteger widthHeight = kScreenWidth - 2 * left;
- NSInteger top = (kScreenHeight - widthHeight) / 2;
- imagePickerVc.cropRect = CGRectMake(left, top, widthHeight, widthHeight);
-
-
-
- imagePickerVc.sortAscendingByModificationDate = NO;
- #pragma mark - 到这里为止
-
-
-
- [imagePickerVc setDidFinishPickingPhotosHandle:^(NSArray<UIImage *> *photos, NSArray *assets, BOOL isSelectOriginalPhoto) {
-
-
- [self evaluateWithChooseImage:[photos lastObject] scaleWidth:NO];
-
- }];
- imagePickerVc.modalPresentationStyle = UIModalPresentationFullScreen;
- [[self getViewController] presentViewController:imagePickerVc animated:YES completion:nil];
- }
- - (void)evaluateWithChooseImage:(UIImage *)image scaleWidth:(BOOL)needScaleWidth {
- dispatch_async(dispatch_get_main_queue(), ^{
- [self uploadImage:image scaleWidth:needScaleWidth];
- });
- }
- - (void)uploadImage:(UIImage *)image scaleWidth:(BOOL)needScaleWidth {
-
- NSData *imgData = [UIImage compressImage:image maxLength:5];
-
- NSString *fileName = @"whiteboardImage";
- [UPLOAD_MANAGER configWithfilePath:@"/whiteboard/"];
- [UPLOAD_MANAGER uploadImage:imgData fileName:fileName successCallback:^(NSMutableArray * _Nonnull fileUrlArray) {
- NSString *imageUrl = [fileUrlArray lastObject];
- [self insertImageWithUrl:imageUrl size:image.size];
-
- } faliure:^(NSError * _Nullable error, NSString * _Nullable descMessaeg) {
- if (![NSString isEmptyString:descMessaeg]) {
- [LOADING_MANAGER MBShowAUTOHidingInWindow:descMessaeg];
- }
- }];
- }
- - (void)insertImageWithUrl:(NSString *)imageUrl size:(CGSize)imageSize {
- NSMutableDictionary *parm = [NSMutableDictionary dictionary];
- if (_isChoosePhoto) {
- self.isChoosePhoto = NO;
- [parm setValue:@"whiteboardSelectPhoto" forKey:@"api"];
- }
- else {
- [parm setValue:@"whiteboardSelectMusicLibrary" forKey:@"api"];
- }
- NSMutableDictionary *content = [NSMutableDictionary dictionary];
- [content setValue:imageUrl forKey:@"url"];
- [parm setValue:content forKey:@"content"];
- [self postMessageJS:parm];
- }
- #pragma mark - UIImagePickerController
- - (void)takePhoto {
-
- AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
- if ((authStatus == AVAuthorizationStatusRestricted || authStatus == AVAuthorizationStatusDenied) && kiOS7Later) {
-
- #pragma clang diagnostic push
- #pragma clang diagnostic ignored "-Wdeprecated-declarations"
- UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"无法使用相机" message:@"请在iPhone的""设置-隐私-相机""中允许访问相机" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"设置", nil];
- [alert show];
- #pragma clang diagnostic pop
- }
- else if (authStatus == AVAuthorizationStatusNotDetermined) {
-
- [AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) {
- if (granted) {
- dispatch_async(dispatch_get_main_queue(), ^{
- [self takePhoto];
- });
- }
- }];
- }
- else if ([PHPhotoLibrary authorizationStatus] == 2) {
- #pragma clang diagnostic push
- #pragma clang diagnostic ignored "-Wdeprecated-declarations"
- UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"无法访问相册" message:@"请在iPhone的""设置-隐私-相册""中允许访问相册" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"设置", nil];
- [alert show];
- #pragma clang diagnostic pop
- }
- else if ([PHPhotoLibrary authorizationStatus] == 0) {
- [[TZImageManager manager] requestAuthorizationWithCompletion:^{
- [self takePhoto];
- }];
- }
- else {
- UIImagePickerControllerSourceType sourceType = UIImagePickerControllerSourceTypeCamera;
- if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera]) {
- self.imagePickerVc.sourceType = sourceType;
- if(kiOS8Later) {
- _imagePickerVc.modalPresentationStyle = UIModalPresentationFullScreen;
- }
- _imagePickerVc.modalPresentationStyle = UIModalPresentationFullScreen;
- [[self getViewController] presentViewController:_imagePickerVc animated:YES completion:nil];
- } else {
- NSLog(@"模拟器中无法打开照相机,请在真机中使用");
- }
- }
- }
- - (void)imagePickerController:(UIImagePickerController*)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
- [picker dismissViewControllerAnimated:YES completion:nil];
- NSString *type = [info objectForKey:UIImagePickerControllerMediaType];
- if ([type isEqualToString:@"public.image"]) {
- TZImagePickerController *tzImagePickerVc = [[TZImagePickerController alloc] initWithMaxImagesCount:MAXPHOTONUMBER delegate:self];
- tzImagePickerVc.allowCrop = YES;
- tzImagePickerVc.needCircleCrop = NO;
- tzImagePickerVc.showSelectBtn = YES;
- tzImagePickerVc.sortAscendingByModificationDate = NO;
-
- [tzImagePickerVc showProgressHUD];
- UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
-
- [[TZImageManager manager] savePhotoWithImage:image completion:^(PHAsset *asset,NSError *error){
- if (error) {
- [tzImagePickerVc hideProgressHUD];
- NSLog(@"图片保存失败 %@",error);
- UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"无法保存图片" message:@"请在iPhone的""设置-隐私-相册""中允许访问相册" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"设置", nil];
- alert.tag = 1;
- [alert show];
- } else {
-
- TZAssetModel *assetModel = [[TZImageManager manager] createModelWithAsset:asset];
-
- TZImagePickerController *imagePicker = [[TZImagePickerController alloc] initCropTypeWithAsset:assetModel.asset photo:image completion:^(UIImage *cropImage, id asset) {
-
- [self evaluateWithChooseImage:cropImage scaleWidth:NO];
- }];
- imagePicker.allowPickingImage = YES;
- imagePicker.allowCrop = YES;
- imagePicker.needCircleCrop = NO;
- NSInteger left = 30;
- NSInteger widthHeight = kScreenWidth - 2 * left;
- NSInteger top = (kScreenHeight - widthHeight) / 2;
- imagePicker.cropRect = CGRectMake(left, top, widthHeight, widthHeight);
- imagePicker.modalPresentationStyle = UIModalPresentationFullScreen;
- [[self getViewController] presentViewController:imagePicker animated:YES completion:nil];
-
- }
- }];
- }
- }
- - (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
- if ([picker isKindOfClass:[UIImagePickerController class]]) {
- [picker dismissViewControllerAnimated:YES completion:nil];
- }
- }
- #pragma mark - getter
- - (NSMutableArray *)imageArray {
- if (!_imageArray) {
- _imageArray = [NSMutableArray array];
- }
- return _imageArray;
- }
- - (NSMutableArray *)imageAsset {
- if (!_imageAsset) {
- _imageAsset = [NSMutableArray array];
- }
- return _imageAsset;
- }
- - (UIImagePickerController *)imagePickerVc {
- if (_imagePickerVc == nil) {
- _imagePickerVc = [[UIImagePickerController alloc] init];
- _imagePickerVc.delegate = self;
-
- _imagePickerVc.navigationBar.barTintColor = THEMECOLOR;
- _imagePickerVc.navigationBar.tintColor = THEMECOLOR;
- UIBarButtonItem *tzBarItem, *BarItem;
- if (kiOS9Later) {
- tzBarItem = [UIBarButtonItem appearanceWhenContainedInInstancesOfClasses:@[[TZImagePickerController class]]];
- BarItem = [UIBarButtonItem appearanceWhenContainedInInstancesOfClasses:@[[UIImagePickerController class]]];
- } else {
- #pragma clang diagnostic push
- #pragma clang diagnostic ignored "-Wdeprecated-declarations"
- tzBarItem = [UIBarButtonItem appearanceWhenContainedIn:[TZImagePickerController class], nil];
- BarItem = [UIBarButtonItem appearanceWhenContainedIn:[UIImagePickerController class], nil];
- #pragma clang diagnostic pop
- }
- NSDictionary *titleTextAttributes = [tzBarItem titleTextAttributesForState:UIControlStateNormal];
- [BarItem setTitleTextAttributes:titleTextAttributes forState:UIControlStateNormal];
- }
- return _imagePickerVc;
- }
- #pragma mark - UIAlertViewDelegate
- #pragma clang diagnostic push
- #pragma clang diagnostic ignored "-Wdeprecated-declarations"
- #pragma clang diagnostic ignored "-Wdeprecated-implementations"
- - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
- if (buttonIndex == 1) {
- [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
- }
- }
- #pragma clang diagnostic pop
- - (UIImageView *)chooseImage {
- if (!_chooseImage) {
- _chooseImage = [[UIImageView alloc] init];
- }
- return _chooseImage;
- }
- - (void)setCurrentFrame:(CGRect)currentFrame {
- _currentFrame = currentFrame;
- self.frame = currentFrame;
- }
- - (void)destroy {
-
- }
- - (void)joinWhiteRoom {
- [self configView:self.bounds];
- if (self.url) {
- [self loadRequest];
- }
- else {
- self.isJoinRoom = YES;
- [LOADING_MANAGER showHUD];
- }
- }
- - (void)leaveRoom {
- self.isJoinRoom = NO;
- [self removeLoadig];
- [[_myWebView configuration].userContentController removeScriptMessageHandlerForName:SCRIPT_NAME];
- [_myWebView loadHTMLString:@"" baseURL:nil];
- [_myWebView removeFromSuperview];
-
- _myWebView = nil;
- [[NSURLCache sharedURLCache] removeAllCachedResponses];
- [[NSURLCache sharedURLCache] setDiskCapacity:0];
- [[NSURLCache sharedURLCache] setMemoryCapacity:0];
- [[NSNotificationCenter defaultCenter] removeObserver:self];
- }
- - (void)showLoading {
- self.isLoadingSource = YES;
- }
- - (void)removeLoadig {
- self.isLoadingSource = NO;
- if (self.isJoinRoom) {
- [LOADING_MANAGER removeHUD];
- [self loadRequest];
- }
- }
- - (void)setConnectedSuccess:(BOOL)connectedSuccess {
- _connectedSuccess = connectedSuccess;
- if (connectedSuccess) {
- self.refreshButton.hidden = YES;
- }
- else {
- self.refreshButton.hidden = NO;
- }
- }
- - (KSWhiteboardRefreshView *)refreshButton {
- if (!_refreshButton) {
- _refreshButton = [KSWhiteboardRefreshView shareInstance];
- MJWeakSelf;
- [_refreshButton refreshActionCallback:^{
- [weakSelf refreshWebViewAction];
- }];
- }
- return _refreshButton;
- }
- - (void)refreshWebViewAction {
-
- if ([NSString isEmptyString:self.url]) {
- [LOADING_MANAGER showHUD];
- [WhiteUtils getRoomTokenWithRoomId:self.roomId completionHandler:^(NSString * _Nullable uuid, NSString * _Nullable roomToken, NSString * _Nonnull randomRoom, NSString * _Nullable randomNumeric, NSError * _Nullable error) {
- [LOADING_MANAGER removeHUD];
- if (!error) {
- NSString *url = [NSString stringWithFormat:@"%@%@?roomId=%@&userId=%@&clientType=STUDENT&role=viewer#room=%@,%@", hostURL, @"/whiteboard/",self.roomId,UserDefault(UIDKey),randomRoom,randomNumeric];
- self.url = url;
- [self refreshRequest];
- }
- }];
- }
- else {
- [self refreshRequest];
- }
-
- }
- - (void)refreshRequest {
- [LOADING_MANAGER showHUD];
- [self loadRequest];
- [LOADING_MANAGER removeHUD];
- }
- - (UIViewController *)getViewController {
- for (UIView *view = self; view; view = view.superview) {
- UIResponder *nextResponder = [view nextResponder];
- if ([nextResponder isKindOfClass:[UIViewController class]]) {
- return (UIViewController *)nextResponder;
- }
- }
- return nil;
- }
- @end
|