| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393 |
- //
- // RAYTPlayer.m
- // iSales-UWAVER
- //
- // Created by Rui Zhang on 11/26/19.
- // Copyright © 2019 United Software Applications, Inc. All rights reserved.
- //
- #import "RAYTPlayer.h"
- @interface RAYTPlayer ()
- //@property (strong, nonatomic) WKWebView *wkwebView;
- //@property (nonatomic,strong) NSDictionary *currentParams;
- //@property (nonatomic,weak) RAProgressHUD *hud;
- //@property (nonatomic,copy) NSString *url;
- //@property (nonatomic,assign) BOOL firstLoad;
- @end
- @implementation RAYTPlayer
- - (instancetype)initWithFrame:(CGRect)frame
- {
- self = [super initWithFrame:frame];
- if (self) {
-
- [self initWKWebView];
- [self initMessageHandler];
- }
- return self;
- }
- - (instancetype)initWithCoder:(NSCoder *)coder
- {
- self = [super initWithCoder:coder];
- if (self) {
-
- [self initWKWebView];
- [self initMessageHandler];
-
- }
- return self;
- }
- - (void)layoutSubviews {
- [super layoutSubviews];
-
- self.wkwebView.frame = self.bounds;
- }
- -(void) initWKWebView
- {
- WKWebViewConfiguration *configuration = [[WKWebViewConfiguration alloc] init];
-
- WKPreferences *preferences = [WKPreferences new];
- preferences.javaScriptCanOpenWindowsAutomatically = false;
- // preferences.minimumFontSize = 40.0;
- configuration.mediaTypesRequiringUserActionForPlayback = WKAudiovisualMediaTypeAll;
- configuration.allowsInlineMediaPlayback = true;
- configuration.allowsPictureInPictureMediaPlayback=false;
- configuration.preferences = preferences;
-
- _wkwebView = [[WKWebView alloc] initWithFrame:self.bounds configuration:configuration];
- self.wkwebView.hidden=YES;
- // self.wkwebView.UIDelegate = self;
-
- self.wkwebView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
- self.wkwebView.navigationDelegate = self;
- self.wkwebView.scrollView.bounces = false;
- [self addSubview:self.wkwebView];
-
- // __weak typeof(self) weakSelf = self;
- // [self.wkwebView.scrollView setEmptyContentViewBackgroupColor:UIColor.whiteColor];
- // self.wkwebView.scrollView.emptyView = [RAEmptyView emptyViewWithTitle:@"can not reach the server.\ntap to reload" clickHandler:^(id sender) {
- // [weakSelf LoadFromURL:weakSelf.url];
- // }];
-
-
- // self.firstLoad = YES;
-
-
-
-
- }
- -(void)LoadWithVid:(NSString *)vid
- {
- if(self.wkwebView==nil)
- return;
- NSString * replacement = [NSString stringWithFormat:@"src=\"https://www.youtube.com/embed/%@\"",vid];
- NSError *error;
- NSString *htmlStr = [NSString stringWithContentsOfFile:[[NSBundle mainBundle]pathForResource:@"ytplayer" ofType:@"html"]encoding:NSUTF8StringEncoding error: & error];
-
- htmlStr=[htmlStr stringByReplacingOccurrencesOfString:@"src=replacement" withString:replacement];
-
-
-
- // NSString *htmlStr1=@"abc def ggg";
- // [htmlStr stringByReplacingOccurrencesOfString:@"src=replacement" withString:replacement];
- // NSString* new_url = [NSString stringWithFormat:@"https://www.youtube.com/embed/%@?playsinline=1",vid];
-
-
-
- // [self.wkwebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:new_url]]];
- [self.wkwebView loadHTMLString:htmlStr baseURL:nil];
- self.wkwebView.hidden=NO;
- }
- -(void)LoadFromURL:(NSString *)vid
- {
- if(self.wkwebView==nil)
- return;
-
- NSString* url = [NSString stringWithFormat:@"https://www.youtube.com/embed/%@?playsinline=1",vid];
- NSURL* U=[NSURL URLWithString:url];
- NSURLRequest* request=[[NSURLRequest alloc]initWithURL:U cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval:30.0f];
-
- [self.wkwebView loadRequest:request];
- }
- -(void) initMessageHandler
- {
- // [self.wkwebView.configuration.userContentController addScriptMessageHandler:self name:@"CamScan"];
- // [self.wkwebView.configuration.userContentController addScriptMessageHandler:self name:@"Location"];
- // [self.wkwebView.configuration.userContentController addScriptMessageHandler:self name:@"Share"];
- // [self.wkwebView.configuration.userContentController addScriptMessageHandler:self name:@"JumpTo"];
- // [self.wkwebView.configuration.userContentController addScriptMessageHandler:self name:@"ViewImage"];
- // [self.wkwebView.configuration.userContentController addScriptMessageHandler:self name:@"PostDialog"];
- // [self.wkwebView.configuration.userContentController addScriptMessageHandler:self name:@"Photo"];
- // [self.wkwebView.configuration.userContentController addScriptMessageHandler:self name:@"Email"];
- // [self.wkwebView.configuration.userContentController addScriptMessageHandler:self name:@"Preview"];
- // [self.wkwebView.configuration.userContentController addScriptMessageHandler:self name:@"Navigation"];
- // [self.wkwebView.configuration.userContentController addScriptMessageHandler:self name:@"DatetimePicker"];
- //
- //// [self.wkwebView.configuration.userContentController addScriptMessageHandler:self name:@"UpdateBadge"];
- //
- // [self.wkwebView.configuration.userContentController addScriptMessageHandler:self name:@"Signature"];
- // [self.wkwebView.configuration.userContentController addScriptMessageHandler:self name:@"SelectContact"];
- // [self.wkwebView.configuration.userContentController addScriptMessageHandler:self name:@"requestApplicationInfo"];
- // [self.wkwebView.configuration.userContentController addScriptMessageHandler:self name:@"cleanCache"];
- //
- // [self.wkwebView.configuration.userContentController addScriptMessageHandler:self name:@"login"];
- // [self.wkwebView.configuration.userContentController addScriptMessageHandler:self name:@"logout"];
- // [self.wkwebView.configuration.userContentController addScriptMessageHandler:self name:@"UpdateBadge"];
- // [self.wkwebView.configuration.userContentController addScriptMessageHandler:self name:@"QueryLaunchNotification"];
- //
- //
- //
- }
- -(void)destroyMessageHandler
- {
- // [self.wkwebView.configuration.userContentController removeScriptMessageHandlerForName:@"CamScan"];
- // [self.wkwebView.configuration.userContentController removeScriptMessageHandlerForName:@"Location"];
- // [self.wkwebView.configuration.userContentController removeScriptMessageHandlerForName:@"Share"];
- // [self.wkwebView.configuration.userContentController removeScriptMessageHandlerForName:@"JumpTo"];
- // [self.wkwebView.configuration.userContentController removeScriptMessageHandlerForName:@"ViewImage"];
- // [self.wkwebView.configuration.userContentController removeScriptMessageHandlerForName:@"PostDialog"];
- // [self.wkwebView.configuration.userContentController removeScriptMessageHandlerForName:@"Photo"];
- // [self.wkwebView.configuration.userContentController removeScriptMessageHandlerForName:@"Email"];
- // [self.wkwebView.configuration.userContentController removeScriptMessageHandlerForName:@"Preview"];
- // [self.wkwebView.configuration.userContentController removeScriptMessageHandlerForName:@"Navigation"];
- // [self.wkwebView.configuration.userContentController removeScriptMessageHandlerForName:@"DatetimePicker"];
- // [self.wkwebView.configuration.userContentController removeScriptMessageHandlerForName:@"Signature"];
- // [self.wkwebView.configuration.userContentController removeScriptMessageHandlerForName:@"SelectContact"];
- // [self.wkwebView.configuration.userContentController removeScriptMessageHandlerForName:@"requestApplicationInfo"];
- // [self.wkwebView.configuration.userContentController removeScriptMessageHandlerForName:@"cleanCache"];
- //
- // [self.wkwebView.configuration.userContentController removeScriptMessageHandlerForName:@"login"];
- // [self.wkwebView.configuration.userContentController removeScriptMessageHandlerForName:@"logout"];
- // [self.wkwebView.configuration.userContentController removeScriptMessageHandlerForName:@"UpdateBadge"];
- // [self.wkwebView.configuration.userContentController removeScriptMessageHandlerForName:@"QueryLaunchNotification"];
-
- }
- - (void)dealloc
- {
- [self destroyMessageHandler];
- }
- #pragma mark - Setter
- - (void)setContentInsetAdjustmentBehavior:(UIScrollViewContentInsetAdjustmentBehavior)contentInsetAdjustmentBehavior {
- self.wkwebView.scrollView.contentInsetAdjustmentBehavior = contentInsetAdjustmentBehavior;
- }
- //
- //#pragma mark - Private
- //
- //- (UIViewController *)ra_viewController {
- // return [RAUtils getViewController:self];
- //}
- //
- //- (void)ra_openPhotoLibrary:(NSDictionary *)params {
- //
- // UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
- // imagePicker.delegate = self;
- // imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
- // imagePicker.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
- // imagePicker.allowsEditing = YES;
- // [self.ra_viewController presentViewController:imagePicker animated:YES completion:nil];
- // self.currentParams = params;
- //}
- //
- //- (void)ra_openCamera:(NSDictionary *)params {
- //
- // RACameraViewController *cameraVC = [RACameraViewController viewControllerFromStoryboard];
- // cameraVC.completion = ^(UIImage *image) {
- //
- // image = [UIImage img_compress:image kbsize:1024];
- // NSData *data = UIImageJPEGRepresentation(image, 1.0);
- //// NSString *name = NSUUID.UUID.UUIDString;
- //// NSString *path = [NSTemporaryDirectory() stringByAppendingPathComponent:name];
- //// [data writeToFile:path atomically:NO];
- //
- // NSString *imageSource = [NSString stringWithFormat:@"data:image/jpg;base64,%@",[data base64EncodedStringWithOptions:NSDataBase64EncodingEndLineWithLineFeed]];
- //
- // [self returnToWebPage:params value:imageSource];
- // };
- //
- // cameraVC.fromVC = self.ra_viewController;
- // [self.ra_viewController.navigationController pushViewController:cameraVC animated:YES];
- //}
- //
- //- (void)ra_openQRCodeScanner:(NSDictionary *)params {
- //
- // RAQRCodeScannerViewController *scanVC = [RAQRCodeScannerViewController viewControllerFromStoryboard];
- //
- // scanVC.QRCodeViewControllerDidCompletion = ^(RAQRCodeScannerViewController *qrcodeViewController, NSString *value) {
- //
- // [self returnToWebPage:params value:value];
- // [qrcodeViewController.navigationController popViewControllerAnimated:YES];
- // };
- //
- // scanVC.QRCodeViewControllerDidCanceled = ^(RAQRCodeScannerViewController *qrcodeViewController) {
- //
- // [qrcodeViewController.navigationController popViewControllerAnimated:YES];
- // };
- //
- // [self.ra_viewController.navigationController pushViewController:scanVC animated:YES];
- //}
- //
- //
- //- (void)ra_previewDocument:(NSDictionary *)params {
- // /**
- // cc = "test1@abc.com,test2@abc.com";
- // content = content;
- // receipt = "test@abc.com";
- // subject = "email subject";
- // url = "http://10.0.0.4:8080/backend_test/test.pdf";
- // */
- //
- // NSString *urlStr = [params objectForKey:@"url"];
- //// urlStr = @"http://192.168.0.130/ios.pdf";
- // if (urlStr) {
- //
- // RAProgressHUD *hud = [RAProgressHUD showHUDOnView:self.ra_viewController.view];
- //
- // // 先下载下来,否则QuickLook分享要崩溃
- // dispatch_async(dispatch_get_global_queue(0, 0), ^{
- //
- // NSString *tmpDir = NSTemporaryDirectory();
- //
- // [RADataProvider GET_DownloadFile:urlStr toFolder:tmpDir progressHandler:^(NSURLSessionTask *task, double progress) {
- //
- // NSLog(@"download %@ progress %f", urlStr.lastPathComponent, progress);
- //
- // } completionHandler:^(NSMutableDictionary *result) {
- //
- // dispatch_async(dispatch_get_main_queue(), ^{
- //
- // [hud dismiss:^{
- //
- // int resultCode = [[result objectForKey:@"result"] intValue];
- // if (resultCode == RESULT_TRUE) {
- //
- // NSString *path = [result objectForKey:@"path"];
- //
- // RAPreviewController *vc = [RAPreviewController ra_previewControllerWithURL:[NSURL fileURLWithPath:path]];
- // [self.ra_viewController presentViewController:vc animated:YES completion:nil];
- //
- // } else {
- //
- // NSString *msg = [result objectForKey:@"msg"];
- // [RAUtils message_alert:msg title:NSLocalizedString(@"warning_title", nil) controller:self.ra_viewController];
- //
- // }
- //
- // }];
- //
- // });
- //
- // }];
- // });
- //
- // }
- //}
- //
- //- (void)ra_mail:(NSDictionary *)params {
- //
- // /**
- //
- // cc = "test1@abc.com,test2@abc.com";
- // content = content;
- // receipt = "test@abc.com";
- // subject = "email subject";
- //
- // */
- // MFMailComposeViewController *mc = [[MFMailComposeViewController alloc] init];
- //
- // if(mc==nil)
- // {
- // return;
- // }
- //
- // NSString *subject = [params objectForKey:@"subject"];
- // NSString *receipt = [params objectForKey:@"receipt"];
- // NSString *content = [params objectForKey:@"content"];
- // NSString *cc = [params objectForKey:@"cc"];
- //
- // mc.mailComposeDelegate = self;
- // [mc setSubject:subject];
- //
- //
- // [mc setToRecipients:[receipt componentsSeparatedByString:@","]];
- // [mc setCcRecipients:[cc componentsSeparatedByString:@","]];
- //
- // if(!content)
- // content=@"";
- //
- // NSString* htmlbody = [NSString stringWithFormat:@"<html><p>%@</p></html>",content];
- //
- // [mc setMessageBody:htmlbody isHTML:YES];
- //
- //
- //// NSString* filename =self.filename;
- ////
- //// NSString *filePath = self.url;
- //// NSData *data = [NSData dataWithContentsOfFile:filePath];
- ////
- //// // if(self.attachment_name.length>0)
- //// // filename = self.attachment_name;
- //// [mc addAttachmentData:data mimeType:@"application/pdf" fileName:filename];
- //
- // [self.ra_viewController presentViewController:mc animated:YES completion:nil];
- // self.currentParams = params;
- //}
- //
- //- (void)ra_share:(NSDictionary *)params {
- //
- //
- //
- // // 设置分享内容
- //
- //// NSString *content = [params objectForKey:@"content"];
- //// NSString *imageURL = [params objectForKey:@"image"];
- //// NSString *title = [params objectForKey:@"title"];
- // NSString *url = [params objectForKey:@"url"];
- //
- // NSArray *activityItems = @[[NSURL URLWithString:url]];
- //
- // // 服务类型控制器
- // UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:@[]];
- // // _activityViewController = activityViewController;
- // // activityViewController.excludedActivityTypes = @[UIActivityTypeMail];
- // activityViewController.modalInPopover = true;
- //
- // // 选中分享类型
- // [activityViewController setCompletionWithItemsHandler:^(NSString * __nullable activityType, BOOL completed, NSArray * __nullable returnedItems, NSError * __nullable activityError){
- // // 显示选中的分享类型
- // NSLog(@"act type %@",activityType);
- //
- //// if (completed) {
- //// NSLog(@"ok");
- //// }else {
- //// NSLog(@"not ok");
- //// }
- // NSMutableDictionary *shareResult = [NSMutableDictionary dictionary];
- // if (!activityType) {
- // activityType = @"cancel";
- // }
- // shareResult[@"to"] = [activityType componentsSeparatedByString:@"."].lastObject;
- // shareResult[@"completed"] = @(completed);
- // if (activityError) {
- // shareResult[@"error"] = activityError.localizedDescription;
- // }
- //
- // [self returnToWebPage:params value:[RAConvertor dict2string:shareResult]];
- //
- // }];
- //
- // [self.ra_viewController presentViewController:activityViewController animated:YES completion:nil];
- //}
- //
- //- (void)ra_viewPhotos:(NSDictionary *)params {
- //
- // NSArray *urlArr = [params objectForKey:@"images"];
- // NSUInteger index = [[params objectForKey:@"index"] integerValue];
- //
- // NSMutableArray *mArr = [NSMutableArray array];
- // for (NSString *url in urlArr) {
- //
- // RAPhotoModel *model = [RAPhotoModel new];
- // model.url = url;
- //
- // [mArr addObject:model];
- // }
- //
- //
- // RAPhotoPreviewController *previewController = [RAPhotoPreviewController ra_photoPreviewControllerWithPhotoItems:mArr offset:index];
- //
- // [self.ra_viewController presentViewController:previewController animated:YES completion:nil];
- //}
- //
- //- (void)ra_navigate:(NSDictionary *)params {
- //
- // NSString *name = [params objectForKey:@"name"];
- // NSString *addr = [params objectForKey:@"address"];
- //
- // [RAMapNavigateHandler ra_navigate:addr withTitle:name viewController:self.ra_viewController];
- //}
- //
- //- (void)ra_signature:(NSDictionary *)params {
- //
- // __weak typeof(self) weakSelf = self;
- // SignatureViewController *signatureVC = [SignatureViewController ra_signatureViewControllerWithCompletion:^(UIImage *image) {
- //
- // NSData *data = UIImageJPEGRepresentation(image, 1.0);
- //
- // NSString *imageSource = [NSString stringWithFormat:@"data:image/jpg;base64,%@",[data base64EncodedStringWithOptions:NSDataBase64EncodingEndLineWithLineFeed]];
- //
- // [weakSelf returnToWebPage:params value:imageSource];
- //
- // }];
- //
- // [self.ra_viewController.navigationController pushViewController:signatureVC animated:NO];
- //}
- //
- //- (void)ra_dateTimePicker:(NSDictionary *)params {
- //
- // NSString *type = [params objectForKey:@"type"];
- // NSString *value = [params objectForKey:@"value"];
- // NSString *title = [params objectForKey:@"title"];
- //
- // NSString *format = @"MM/dd/yyyy";
- // UIDatePickerMode mode = UIDatePickerModeDate;
- //
- //// type = @"dateTime";
- //// value = @"09/22/1028 14:44:24";
- //
- // if ([type isEqualToString:@"date"]) {
- //
- // } else if ([type isEqualToString:@"time"]) {
- //
- // format = @"HH:mm:ss";
- // mode = UIDatePickerModeTime;
- //
- // } else if ([type isEqualToString:@"dateTime"]) {
- //
- // format = @"MM/dd/yyyy HH:mm:ss";
- // mode = UIDatePickerModeDateAndTime;
- // }
- //
- // NSDateFormatter *dateFormatter = [NSDateFormatter new];
- // dateFormatter.dateFormat = format;
- // NSDate *date = [dateFormatter dateFromString:value];
- //
- // __weak typeof(self) weakSelf = self;
- // [RADatePickerViewController presentDatePicker:self.ra_viewController title:title dateMode:mode defaultDate:date withSetBlk:^(NSDate *date) {
- //
- // NSString *dateStr = [dateFormatter stringFromDate:date];
- // [weakSelf returnToWebPage:params value:dateStr];
- // }];
- //}
- //
- //- (void)ra_selectContact:(NSDictionary *)params {
- //
- // __weak typeof(self) weakSelf = self;
- // [[RAContactHelper defaultHelper] showContactPickerByViewController:self.ra_viewController withComplete:^(BOOL canceled, NSArray<CNContact *> *contacts) {
- //
- // if (!canceled) {
- //
- // NSMutableArray *contactArray = [NSMutableArray array];
- // for (CNContact *contact in contacts) {
- //
- // NSMutableDictionary *contactDictionary = [NSMutableDictionary dictionary];
- // NSLog(@"=========================================================");
- // // givenName middleName familyName
- // NSString *givenName = [self adjustNilString:contact.givenName];
- // NSString *middleName = [self adjustNilString:contact.middleName];
- // NSString *familyName = [self adjustNilString:contact.familyName];
- // NSString *name = [NSString stringWithFormat:@"%@ %@ %@", givenName, middleName, familyName];
- //
- // NSLog(@"=======================Contact Name=======================");
- // NSLog(@"%@",name);
- // contactDictionary[@"name"] = name;
- //
- // // organizationName departmentName jobTitle
- // NSString *organizationName = [self adjustNilString:contact.organizationName];
- // NSString *departmentName = [self adjustNilString:contact.departmentName];
- // NSString *jobTitle = [self adjustNilString:contact.jobTitle];
- // NSString *job = [NSString stringWithFormat:@"%@ %@ %@", organizationName, departmentName, jobTitle];
- //
- // NSLog(@"=======================Contact Job=======================");
- // NSLog(@"%@",job);
- // contactDictionary[@"job"] = @[job];
- //
- // // phoneNumbers emailAddresses postalAddresses urlAddresses
- //
- // NSMutableArray *phoneArray = [NSMutableArray array];
- // NSMutableArray *faxArray = [NSMutableArray array];
- // NSLog(@"=======================Phone Number=======================");
- // NSArray<CNLabeledValue<CNPhoneNumber*>*> *phoneNumbers = contact.phoneNumbers;
- // for (CNLabeledValue<CNPhoneNumber*> *labeledValue in phoneNumbers) {
- //
- // CNPhoneNumber *phoneNumber = labeledValue.value;
- // NSString *label = [CNLabeledValue localizedStringForLabel:labeledValue.label];
- // NSLog(@"%@ %@", label, phoneNumber.stringValue);
- //
- // if ([labeledValue.label.lowercaseString containsString:@"fax"]) {
- // [faxArray addObject:phoneNumber.stringValue];
- // } else {
- // [phoneArray addObject:phoneNumber.stringValue];
- // }
- // }
- // contactDictionary[@"phone"] = phoneArray;
- // contactDictionary[@"fax"] = faxArray;
- //
- // NSMutableArray *emailArray = [NSMutableArray array];
- // NSLog(@"=======================Email Address=======================");
- // NSArray<CNLabeledValue<NSString*>*> *emailAddresses = contact.emailAddresses;
- // for (CNLabeledValue<NSString*> *labeledValue in emailAddresses) {
- //
- // NSString *email = labeledValue.value;
- // NSString *label = [CNLabeledValue localizedStringForLabel:labeledValue.label];
- // NSLog(@"%@ %@", label, email);
- // [emailArray addObject:email];
- // }
- // contactDictionary[@"email"] = emailArray;
- //
- // NSMutableArray *addressArray = [NSMutableArray array];
- // NSLog(@"=======================Postal Number=======================");
- // NSArray<CNLabeledValue<CNPostalAddress*>*> *postalAddresses = contact.postalAddresses;
- // for (CNLabeledValue<CNPostalAddress*> *labeledValue in postalAddresses) {
- //
- // NSString *label = [CNLabeledValue localizedStringForLabel:labeledValue.label];
- // CNPostalAddress *postalAddress = labeledValue.value;
- // NSString *postalCode = [self adjustNilString:postalAddress.postalCode];
- // NSString *country = [self adjustNilString:postalAddress.country];
- // NSString *state = [self adjustNilString:postalAddress.state];
- // NSString *city = [self adjustNilString:postalAddress.city];
- // NSString *street = [self adjustNilString:postalAddress.street];
- //
- // NSMutableDictionary *addressDic = [NSMutableDictionary dictionary];
- // addressDic[@"postalCode"] = postalCode;
- // addressDic[@"country"] = country;
- // addressDic[@"state"] = state;
- // addressDic[@"city"] = city;
- // addressDic[@"street"] = street;
- //
- // [addressArray addObject:addressDic];
- // NSLog(@"%@ %@ %@ %@ %@ %@", label, postalCode, country, state, city, street);
- // }
- // contactDictionary[@"address"] = addressArray;
- //
- // NSMutableArray *urlArray = [NSMutableArray array];
- // NSLog(@"=======================URL Address=======================");
- // NSArray<CNLabeledValue<NSString*>*> *urlAddresses = contact.urlAddresses;
- // for (CNLabeledValue<NSString*> *labeledValue in urlAddresses) {
- //
- // NSString *url = labeledValue.value;
- // NSString *label = [CNLabeledValue localizedStringForLabel:labeledValue.label];
- // NSLog(@"%@ %@", label, url);
- //
- // [urlArray addObject:url];
- // }
- // contactDictionary[@"url"] = urlArray;
- //
- // NSLog(@"**********************************************************");
- //
- // [contactArray addObject:contactDictionary];
- // }
- //
- // // return
- //
- // NSString *jsonString = [RAConvertor DataTOjsonString:contactArray];
- // [weakSelf returnToWebPage:params value:jsonString];
- //
- // NSLog(@"%@", jsonString);
- // }
- //
- // }];
- //}
- //
- //- (void)ra_requestAppInfo:(NSDictionary *)params {
- //
- // AppDelegate *delagate =(AppDelegate *) [[UIApplication sharedApplication]delegate];
- //
- // NSDictionary *infoDic = [[NSBundle mainBundle] infoDictionary];
- // NSString *ver = [infoDic objectForKey:@"CFBundleShortVersionString"];
- // NSString *build = [infoDic objectForKey:@"CFBundleVersion"];
- // NSString *appVer = [NSString localizedStringWithFormat:@"Ver: %@ build %@",ver,build];
- //
- // NSMutableDictionary * ret = [NSMutableDictionary new];
- // ret[@"appVer"]=appVer;
- // ret[@"apnToken"]=delagate.apnToken ;
- //
- // NSString* Sret=[RAConvertor dict2string:ret];
- // [self returnToWebPage:params value:Sret];
- //}
- //
- //- (void)ra_queryLaunchNotification:(NSDictionary *)params {
- //
- // AppDelegate *delagate =(AppDelegate *) [[UIApplication sharedApplication]delegate];
- //
- //// NSDictionary *infoDic = [[NSBundle mainBundle] infoDictionary];
- //// NSString *ver = [infoDic objectForKey:@"CFBundleShortVersionString"];
- //// NSString *build = [infoDic objectForKey:@"CFBundleVersion"];
- //// NSString *appVer = [NSString localizedStringWithFormat:@"Ver: %@ build %@",ver,build];
- ////
- //// NSMutableDictionary * ret = [NSMutableDictionary new];
- //// ret[@"appVer"]=appVer;
- //// ret[@"apnToken"]=delagate.apnToken ;
- ////
- //// NSString* Sret=[RAConvertor dict2string:ret];
- // [self returnToWebPage:params value:delagate.launchNotification];
- // delagate.launchNotification = nil;
- //
- //}
- //
- //- (void)ra_cleanCache:(NSDictionary *)params {
- //
- // /**
- //
- // // On-disk caches.
- // WKWebsiteDataTypeDiskCache API_AVAILABLE(macosx(10.11), ios(9.0));
- //
- // // In-memory caches.
- // WKWebsiteDataTypeMemoryCache API_AVAILABLE(macosx(10.11), ios(9.0));
- //
- // // HTML offline web application caches.
- // WKWebsiteDataTypeOfflineWebApplicationCache API_AVAILABLE(macosx(10.11), ios(9.0));
- //
- // // Cookies.
- // WKWebsiteDataTypeCookies API_AVAILABLE(macosx(10.11), ios(9.0));
- //
- // // HTML session storage.
- // WKWebsiteDataTypeSessionStorage API_AVAILABLE(macosx(10.11), ios(9.0));
- //
- // // HTML local storage.
- // WKWebsiteDataTypeLocalStorage API_AVAILABLE(macosx(10.11), ios(9.0));
- //
- // // WebSQL databases.
- // WKWebsiteDataTypeWebSQLDatabases API_AVAILABLE(macosx(10.11), ios(9.0));
- //
- // // IndexedDB databases.
- // WKWebsiteDataTypeIndexedDBDatabases API_AVAILABLE(macosx(10.11), ios(9.0));
- //
- // */
- //
- // NSArray *typeArr = @[
- // WKWebsiteDataTypeDiskCache,
- // WKWebsiteDataTypeMemoryCache,
- // WKWebsiteDataTypeOfflineWebApplicationCache,
- // WKWebsiteDataTypeLocalStorage,
- // WKWebsiteDataTypeWebSQLDatabases,
- // WKWebsiteDataTypeIndexedDBDatabases
- // ];
- // NSSet *typeSet = [NSSet setWithArray:typeArr];
- // NSDate *dateSince = [NSDate dateWithTimeIntervalSince1970:0];
- //
- // [[WKWebsiteDataStore defaultDataStore] removeDataOfTypes:typeSet modifiedSince:dateSince completionHandler:^{
- // [self returnToWebPage:params value:@""];
- // }];
- //}
- //
- //- (void)ra_handleLogin:(NSString *)user password:(NSString *)password {
- //
- // if (self.delegate && [self.delegate respondsToSelector:@selector(webview:didLogin:password:)]) {
- // [self.delegate webview:self didLogin:user password:password];
- // }
- //}
- //
- //- (void)ra_handleLogout {
- //
- // if (self.delegate && [self.delegate respondsToSelector:@selector(webviewDidLogout:)]) {
- // [self.delegate webviewDidLogout:self];
- // }
- //}
- #pragma mark - player
- //- (void)stringFromEvaluatingJavaScript:(NSString *)jsToExecute {
- // // return [self.wkwebView stringByEvaluatingJavaScriptFromString:jsToExecute];
- //
- //
- //[self.wkwebView evaluateJavaScript:jsToExecute completionHandler:^(id _Nullable result, NSError * _Nullable error) {
- // NSLog(@"%@----%@",result, error);
- // }];
- //
- //}
- - (void)stopVideo {
-
-
- [self.wkwebView reload];
-
- }
- #pragma mark - Utils
- - (NSString *)adjustNilString:(NSString *)str {
- if (str) {
- return str;
- }
- return @"";
- }
- //- (void)ra_injectJS:(NSString *)js {
- //
- //// NSStringEncoding encoding = NSUTF8StringEncoding;
- //// NSString *js = [NSString stringWithContentsOfFile:@"/Users/macmini1/eclipse-workspace/MyWeb/WebContent/JS/Interface.js" usedEncoding:&encoding error:nil];
- //
- // if (js) {
- // [self.wkwebView evaluateJavaScript:js completionHandler:^(id _Nullable result, NSError * _Nullable error) {
- // NSLog(@"create JS %@ Error: %@", result, error);
- // }];
- // }
- //}
- //
- //#pragma mark - Web Callback
- //
- //-(void) returnToWebPage:(NSDictionary*)params value:(NSString*)value
- //{
- // if(![params isNull:@"returnid"] )
- // {
- //
- // [self webPageReturn:params[@"returnid"] value:value];
- //
- // }else if(![params isNull:@"callback"])
- // {
- // [self webPageCallback:params caller:params[@"id"] value:value];
- // }
- //}
- //-(void) webPageCallback:(NSDictionary*)params caller:(NSString*) callerid value:(NSString*)value
- //{
- //// NSString* caller = [NSString stringWithFormat:@"'%@'",callerid];
- // NSString *caller = [callerid ra_stringByEscapingForJavascriptWithDelimiter:'\'' wrapWithDelimiters:YES];
- // if(value==nil)
- // value=@"";
- //// if([value isKindOfClass:NSString.class])
- // {
- //// value =[NSString stringWithFormat:@"'%@'",value];
- // value = [(NSString *)value ra_stringByEscapingForJavascriptWithDelimiter:'\'' wrapWithDelimiters:YES];
- // }
- //
- // NSString *jsStr = [NSString stringWithFormat:params[@"callback"],caller.UTF8String,value.UTF8String];
- // [self.wkwebView evaluateJavaScript:jsStr completionHandler:^(id _Nullable result, NSError * _Nullable error) {
- // NSLog(@"%@----%@",result, error);
- // }];
- //}
- //-(void) webPageReturn:(NSString*) returnid value:(NSObject*)value
- //{
- // if (returnid && value) {
- //
- // returnid = [returnid ra_stringByEscapingForJavascriptWithDelimiter:'\'' wrapWithDelimiters:YES];
- // value = [value.description ra_stringByEscapingForJavascriptWithDelimiter:'\'' wrapWithDelimiters:YES];
- // NSString *jsStr = [NSString stringWithFormat:@"document.getElementById(%@).value = %@;",returnid,value];
- //
- //// NSString *jsStr = [NSString stringWithFormat:@"document.getElementById(\"%@\").value = \"%@\";",returnid,value];
- // [self.wkwebView evaluateJavaScript:jsStr completionHandler:^(id _Nullable result, NSError * _Nullable error) {
- // NSLog(@"%@----%@",result, error);
- // }];
- //
- // }
- //}
- //
- //- (void)evaluateJs:(NSString *)js completionHandler:(void (^) (id result, NSError *error))handler {
- // [self.wkwebView evaluateJavaScript:js completionHandler:handler];
- //}
- //
- //#pragma mark - MFMailComposeViewControllerDelegate delegate
- //
- //- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error {
- // NSString *resultStr = nil;
- // switch (result)
- // {
- // case MFMailComposeResultCancelled:
- // resultStr = @"email canceled";
- // break;
- // case MFMailComposeResultSaved:
- // resultStr = @"email saved";
- // break;
- // case MFMailComposeResultSent:
- // resultStr = @"email send";
- // break;
- // case MFMailComposeResultFailed:
- // resultStr = [NSString stringWithFormat:@"email error: %@",[error localizedDescription]];
- // break;
- // default:
- // break;
- // }
- //
- // [self returnToWebPage:self.currentParams value:resultStr];
- // self.currentParams = nil;
- //
- // [controller dismissViewControllerAnimated:YES completion:nil];
- //}
- //
- //
- //#pragma mark - UIImagePickerControllerDelegate
- //
- //- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<UIImagePickerControllerInfoKey,id> *)info {
- //
- // if (picker.sourceType == UIImagePickerControllerSourceTypePhotoLibrary) {
- //
- // UIImage *image = [info objectForKey:UIImagePickerControllerEditedImage];
- // image = [UIImage img_compress:image kbsize:1024];
- //
- // [picker dismissViewControllerAnimated:YES completion:nil];
- //
- // NSData *data = UIImageJPEGRepresentation(image, 1.0);
- // NSString *imageSource = [NSString stringWithFormat:@"data:image/jpg;base64,%@",[data base64EncodedStringWithOptions:NSDataBase64EncodingEndLineWithLineFeed]];
- //
- // [self returnToWebPage:self.currentParams value:imageSource];
- // self.currentParams = nil;
- //
- // }
- //}
- //
- //- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
- // [picker dismissViewControllerAnimated:YES completion:nil];
- //}
- //#pragma mark - WKUIDelegate
- //- (void)webView:(WKWebView *)webView runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(void))completionHandler
- //{
- //
- // UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提醒" message:message preferredStyle:UIAlertControllerStyleAlert];
- // [alert addAction:[UIAlertAction actionWithTitle:@"知道了" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
- // if(completionHandler)
- // completionHandler();
- // }]];
- //
- // UIViewController* vc=[RAUtils getViewController:self];
- // [vc presentViewController:alert animated:YES completion:nil];
- //
- //// UIViewController* vc=[self getViewController];
- //// [vc presentViewController:alert animated:YES completion:nil];
- //}
- //-(UIViewController*) getViewController
- //{
- // for (UIView* next = [self superview]; next; next = next.superview) {
- // UIResponder* nextResponder = [next nextResponder];
- // if ([nextResponder isKindOfClass:[UIViewController class]]) {
- // return (UIViewController*)nextResponder;
- // }
- // }
- // return nil;
- //}
- //
- //#pragma mark - WKScriptMessageHandler
- //- (void)userContentController:(WKUserContentController *)userContentController didReceiveScriptMessage:(WKScriptMessage *)message
- //{
- // // message.body -- Allowed types are NSNumber, NSString, NSDate, NSArray,NSDictionary, and NSNull.
- // NSLog(@"%@",message.name);
- // NSLog(@"body:%@",message.body);
- //
- //
- // NSDictionary* params=[RAConvertor string2dict:message.body];
- //// RAConvertor
- // if ([message.name isEqualToString:@"CamScan"]) {
- //
- // [self handleCamScan:params];
- // } else if ([message.name isEqualToString:@"Location"]) {
- //
- // [self handleLocation:params];
- // } else if ([message.name isEqualToString:@"Share"]) {
- //
- // [self handleShare:params];
- // } else if ([message.name isEqualToString:@"JumpTo"]) {
- //
- //
- // [self handleJumpTo:params];
- // } else if ([message.name isEqualToString:@"ViewImage"]) {
- //
- //
- // [self handleViewImage:params];
- // } else if ([message.name isEqualToString:@"PostDialog"]) {
- //
- //
- // [self handlePostDialog:params];
- // }else if ([message.name isEqualToString:@"Photo"]) {
- //
- //
- // [self handlePhoto:params];
- // }else if ([message.name isEqualToString:@"Email"]) {
- //
- //
- //
- // [self handleEmail:params];
- // }else if ([message.name isEqualToString:@"Preview"]) {
- //
- //
- //
- // [self handlePreview:params];
- // }else if ([message.name isEqualToString:@"Navigation"]) {
- //
- //
- //
- // [self handleNavigation:params];
- // }else if ([message.name isEqualToString:@"Signature"]) {
- //
- //
- //
- // [self handleSignature:params];
- // }else if ([message.name isEqualToString:@"DatetimePicker"]) {
- //
- //
- //
- // [self handleDatetimePicker:params];
- // } else if ([message.name isEqualToString:@"SelectContact"]) {
- //
- // [self handleSelectContact:params];
- // } else if ([message.name isEqualToString:@"requestApplicationInfo"]) {
- //
- // [self handleRequestApplicationInfo: params];
- // }else if ([message.name isEqualToString:@"QueryLaunchNotification"]) {
- //
- // [self ra_queryLaunchNotification: params];
- // }
- //
- // else if ([message.name isEqualToString:@"UpdateBadge"]) {
- //
- // [self handleUpdateBadge: params];
- // } else if ([message.name isEqualToString:@"cleanCache"]) {
- //
- // [self handleCleanCache:params];
- // } else if ([message.name isEqualToString:@"login"]) {
- //
- // [self handleLogin:params];
- // } else if ([message.name isEqualToString:@"logout"]) {
- //
- // [self handleLogout];
- // }
- // else
- // {
- // NSLog(@"%@",params);
- // }
- //}
- //
- //- (void)handleDatetimePicker:(NSDictionary *)params
- //{
- //
- //
- // NSLog(@"handleDatetimePicker %@",params);
- //
- // [self ra_dateTimePicker:params];
- //}
- //
- //- (void)handleSignature:(NSDictionary *)params
- //{
- // [self ra_signature:params];
- //}
- //
- //- (void)handleCamScan:(NSDictionary *)params
- //{
- // [self ra_openQRCodeScanner:params];
- //}
- //
- //- (void)handleLocation:(NSDictionary *)params
- //{
- // [self returnToWebPage:params value:@"abc,def,'aaa"];
- //}
- //
- //- (void)handleShare:(NSDictionary *)params
- //{
- // [self ra_share:params];
- //}
- //
- //- (void)handleViewImage:(NSDictionary *)params
- //{
- // [self ra_viewPhotos:params];
- //}
- //
- //- (void)handlePostDialog:(NSDictionary *)params
- //{
- // UIAlertController *alert = [UIAlertController alertControllerWithTitle:params[@"title"] message:params[@"message"] preferredStyle:UIAlertControllerStyleAlert];
- //
- // NSArray* arr_btns=params[@"buttons"];
- // for(int i=0;i<arr_btns.count;i++)
- // {
- // NSDictionary* button = arr_btns[i];
- // [alert addAction:[UIAlertAction actionWithTitle:button[@"text"] style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
- //
- // [self returnToWebPage:params value:button[@"value"]];
- //// NSString *jsStr = [NSString stringWithFormat:params[@"callback"],button[@"value"]];
- //// [self.wkwebView evaluateJavaScript:jsStr completionHandler:^(id _Nullable result, NSError * _Nullable error) {
- //// NSLog(@"%@----%@",result, error);
- //// }];
- // }]];
- // }
- // UIViewController* vc=[RAUtils getViewController:self];
- // [vc presentViewController:alert animated:YES completion:nil];
- //
- //}
- //
- //- (void)handlePhoto:(NSDictionary *)params
- //{
- //
- // UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
- // UIAlertAction *photoLibraryAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"wb_photo_libray_action", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
- // [self ra_openPhotoLibrary:params];
- // }];
- // [alertVC addAction:photoLibraryAction];
- //
- // UIAlertAction *cameraAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"wb_camera_action", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
- // [self ra_openCamera:params];
- // }];
- // [alertVC addAction:cameraAction];
- //
- // UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"btn_cancel", nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
- //
- // }];
- // [alertVC addAction:cancelAction];
- //
- // [self.ra_viewController presentViewController:alertVC animated:YES completion:nil];
- //}
- //
- //- (void)handleEmail:(NSDictionary *)params
- //{
- // [self ra_mail:params];
- //}
- //
- //- (void)handlePreview:(NSDictionary *)params
- //{
- // [self ra_previewDocument:params];
- //}
- //
- //- (void)handleNavigation:(NSDictionary *)params
- //{
- // [self ra_navigate:params];
- //}
- //
- //- (void)handleJumpTo:(NSDictionary *)params
- //{
- //
- // if(self.JumpTo!=nil)
- // {
- // self.JumpTo(params[@"url"], params[@"ios_module"]);
- // return;
- // }
- //// UIViewController* vc=[self getViewController];
- //
- //}
- //
- //- (void)handleSelectContact:(NSDictionary *)params {
- //
- // [self ra_selectContact:params];
- //}
- //
- //- (void)handleUpdateBadge:(NSDictionary *)params {
- // [UIApplication sharedApplication].applicationIconBadgeNumber = [params[@"count"] intValue];
- //// [self ra_requestAppInfo:params];
- //}
- //- (void)handleRequestApplicationInfo:(NSDictionary *)params {
- // [self ra_requestAppInfo:params];
- //}
- //- (void)QueryLaunchNotification:(NSDictionary *)params {
- // [self ra_requestAppInfo:params];
- //}
- //
- //- (void)handleCleanCache:(NSDictionary *)params {
- // [self ra_cleanCache:params];
- //}
- //
- //- (void)handleLogin:(NSDictionary *)params {
- //
- // NSString *user = params[@"user"];
- // NSString *password = params[@"password"];
- // [self ra_handleLogin:user password:password];
- //}
- //
- //- (void)handleLogout {
- // [self ra_handleLogout];
- //}
- //
- //#pragma mark - WKNavigationDelegate
- //
- //- (void)webView:(WKWebView *)webView didReceiveServerRedirectForProvisionalNavigation:(WKNavigation *)navigation {
- // NSLog(@"%s",__func__);
- //}
- //
- //- (void)webView:(WKWebView *)webView didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition, NSURLCredential * _Nullable))completionHandler {
- // NSLog(@"%s",__func__);
- //
- //
- // //1)获取trust object
- // SecTrustRef trust = challenge.protectionSpace.serverTrust;
- // SecTrustResultType result;
- //
- // //2)SecTrustEvaluate对trust进行验证
- // OSStatus status = SecTrustEvaluate(trust, &result);
- //
- // // CFArrayRef defaultPolicies = NULL;
- // // SecTrustCopyPolicies(trust, &defaultPolicies);
- // // NSLog(@"default policies: %@",(__bridge id)defaultPolicies);
- //
- // NSMutableArray *policies = [NSMutableArray array];
- // [policies addObject:(__bridge_transfer id)SecPolicyCreateBasicX509()];
- // SecTrustSetPolicies(trust, (__bridge CFArrayRef)policies);
- //
- // if (status == errSecSuccess && (result == kSecTrustResultProceed || result == kSecTrustResultUnspecified)) {
- //
- // //3)验证成功,生成NSURLCredential凭证cred,告知challenge的sender使用这个凭证来继续连接
- // NSURLCredential *cred = [NSURLCredential credentialForTrust:trust];
- // [challenge.sender useCredential:cred forAuthenticationChallenge:challenge];
- // if (completionHandler) {
- // completionHandler(NSURLSessionAuthChallengeUseCredential,cred); // 使用证书
- // }
- //
- // } else {
- //
- // [challenge.sender cancelAuthenticationChallenge:challenge];
- //
- // //4)验证失败,取消这次验证流程
- // if (completionHandler) {
- // completionHandler(NSURLSessionAuthChallengeCancelAuthenticationChallenge,nil); // 忽略证书
- // }
- //
- // }
- //
- //}
- //
- //
- //- (void)webView:(WKWebView *)webView didFailNavigation:(WKNavigation *)navigation withError:(NSError *)error
- //{
- // NSLog(@"%@",error);
- //}
- //
- ////禁止链接跳转
- //- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler {
- //
- // NSLog(@"%s",__func__);
- // NSLog(@"navigationAction = %@, \r!!!!!!!!!!!!!!!!!!!!!!\n request = %@",navigationAction,navigationAction.request.URL);
- //
- // NSString *url = navigationAction.request.URL.absoluteString;
- // if (![url containsString:[NSBundle mainBundle].bundleURL.absoluteString]) {
- // self.url = url;
- // }
- //
- //
- // decisionHandler(WKNavigationActionPolicyAllow);
- //}
- //
- //- (void)webView:(WKWebView *)webView didStartProvisionalNavigation:(WKNavigation *)navigation {
- // NSLog(@"%s",__func__);
- // @synchronized (self) {
- // [self.wkwebView.scrollView hideEmpty];
- // if (self.firstLoad && !self.hud) {
- // self.hud = [RAProgressHUD showHUDOnView:self.ra_viewController.view];
- // }
- // if (self.delegate && [self.delegate respondsToSelector:@selector(webviewDidStarLoading:)]) {
- // [self.delegate webviewDidStarLoading:self];
- // }
- // }
- //}
- //
- //- (void)webView:(WKWebView *)webView didFailProvisionalNavigation:(WKNavigation *)navigation withError:(NSError *)error {
- // NSLog(@"%s",__func__);
- // NSLog(@"error: %@", error.localizedDescription);
- // @synchronized (self) {
- // if (self.hud) {
- // [self.hud dismiss];
- // self.hud = nil;
- // }
- //
- // if (self.delegate && [self.delegate respondsToSelector:@selector(webviewDidFinishLoading:error:)]) {
- // [self.delegate webviewDidFinishLoading:self error:error];
- // }
- //
- // // NSURL *bundleURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]];
- // // [webView loadHTMLString:@"<html></html>" baseURL:bundleURL];
- //
- // [self.wkwebView.scrollView showEmpty];
- // }
- //}
- //
- //- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation
- //{
- // NSLog(@"%s",__func__);
- // @synchronized (self) {
- // if (self.hud) {
- // [self.hud dismiss];
- // self.hud = nil;
- // self.firstLoad = NO;
- // }
- //
- // if (self.delegate && [self.delegate respondsToSelector:@selector(webviewDidFinishLoading:error:)]) {
- // [self.delegate webviewDidFinishLoading:self error:nil];
- // }
- //
- // // self.wkwebView.scrollView.scrollEnabled = NO;
- // [webView evaluateJavaScript:@"document.body.scrollHeight" completionHandler:^(id result, NSError *_Nullable error) {
- //
- // NSLog(@"web page height:%@",result);
- // //result 就是加载完成后 webView的实际高度
- // //获取后返回重新布局
- //
- // }];
- // }
- //
- //// NSStringEncoding encoding = NSUTF8StringEncoding;
- //// NSString *js = [NSString stringWithContentsOfFile:@"/Users/macmini1/eclipse-workspace/MyWeb/WebContent/JS/Interface.js" usedEncoding:&encoding error:nil];
- //// [self ra_injectJS:js];
- ////
- // // css
- // // /Users/macmini1/eclipse-workspace/MyWeb/WebContent/test.css
- //// NSString *cssJs = [NSString stringWithFormat:];
- //
- //}
- //
- //- (void)webView:(WKWebView *)webView didCommitNavigation:(WKNavigation *)navigation {
- // NSLog(@"%s",__func__);
- //}
- //
- //- (void)webViewWebContentProcessDidTerminate:(WKWebView *)webView {
- // NSLog(@"%s",__func__);
- //}
- //
- //- (void)webView:(WKWebView *)webView decidePolicyForNavigationResponse:(WKNavigationResponse *)navigationResponse decisionHandler:(void (^)(WKNavigationResponsePolicy))decisionHandler
- //{
- // NSLog(@"%s",__func__);
- // decisionHandler(WKNavigationResponsePolicyAllow);
- //}
- #pragma mark - WKNavigationDelegate
- - (void)webView:(WKWebView *)webView didReceiveServerRedirectForProvisionalNavigation:(WKNavigation *)navigation {
- NSLog(@"%s",__func__);
- }
- - (void)webView:(WKWebView *)webView didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition, NSURLCredential * _Nullable))completionHandler {
- NSLog(@"%s",__func__);
-
-
- //1)获取trust object
- SecTrustRef trust = challenge.protectionSpace.serverTrust;
- SecTrustResultType result;
-
- //2)SecTrustEvaluate对trust进行验证
- OSStatus status = SecTrustEvaluate(trust, &result);
-
- // CFArrayRef defaultPolicies = NULL;
- // SecTrustCopyPolicies(trust, &defaultPolicies);
- // NSLog(@"default policies: %@",(__bridge id)defaultPolicies);
-
- NSMutableArray *policies = [NSMutableArray array];
- [policies addObject:(__bridge_transfer id)SecPolicyCreateBasicX509()];
- SecTrustSetPolicies(trust, (__bridge CFArrayRef)policies);
-
- if (status == errSecSuccess && (result == kSecTrustResultProceed || result == kSecTrustResultUnspecified)) {
-
- //3)验证成功,生成NSURLCredential凭证cred,告知challenge的sender使用这个凭证来继续连接
- NSURLCredential *cred = [NSURLCredential credentialForTrust:trust];
- [challenge.sender useCredential:cred forAuthenticationChallenge:challenge];
- if (completionHandler) {
- completionHandler(NSURLSessionAuthChallengeUseCredential,cred); // 使用证书
- }
-
- } else {
-
- [challenge.sender cancelAuthenticationChallenge:challenge];
-
- //4)验证失败,取消这次验证流程
- if (completionHandler) {
- completionHandler(NSURLSessionAuthChallengeCancelAuthenticationChallenge,nil); // 忽略证书
- }
-
- }
- }
- - (void)webView:(WKWebView *)webView didFailNavigation:(WKNavigation *)navigation withError:(NSError *)error
- {
- NSLog(@"%@",error);
- }
- //禁止链接跳转
- - (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler {
-
- NSLog(@"%s",__func__);
- NSLog(@"navigationAction = %@, \r!!!!!!!!!!!!!!!!!!!!!!\n request = %@",navigationAction,navigationAction.request.URL);
- // NSURLRequest * request = navigationAction.request;
- return decisionHandler(WKNavigationActionPolicyAllow);
- // if ([request.URL.host isEqual: self.originURL.host]) {
- // return decisionHandler(WKNavigationActionPolicyAllow);
- // } else if ([request.URL.scheme isEqual:@"ytplayer"]) {
- // [self notifyDelegateOfYouTubeCallbackUrl:request.URL];
- // return decisionHandler(WKNavigationActionPolicyCancel);
- // } else if ([request.URL.scheme isEqual: @"http"] || [request.URL.scheme isEqual:@"https"]) {
- // if( [self handleHttpNavigationToUrl:request.URL])
- // return decisionHandler(WKNavigationActionPolicyAllow);
- // else
- // return decisionHandler(WKNavigationActionPolicyCancel);
- // }
- // return decisionHandler(WKNavigationActionPolicyAllow);
- }
- //
- //- (void)webView:(WKWebView *)webView didStartProvisionalNavigation:(WKNavigation *)navigation {
- // NSLog(@"%s",__func__);
- // @synchronized (self) {
- // [self.wkwebView.scrollView hideEmpty];
- // if (self.firstLoad && !self.hud) {
- // self.hud = [RAProgressHUD showHUDOnView:self.ra_viewController.view];
- // }
- // if (self.delegate && [self.delegate respondsToSelector:@selector(webviewDidStarLoading:)]) {
- // [self.delegate webviewDidStarLoading:self];
- // }
- // }
- //}
- //
- //- (void)webView:(WKWebView *)webView didFailProvisionalNavigation:(WKNavigation *)navigation withError:(NSError *)error {
- // NSLog(@"%s",__func__);
- // NSLog(@"error: %@", error.localizedDescription);
- // @synchronized (self) {
- // if (self.hud) {
- // [self.hud dismiss];
- // self.hud = nil;
- // }
- //
- // if (self.delegate && [self.delegate respondsToSelector:@selector(webviewDidFinishLoading:error:)]) {
- // [self.delegate webviewDidFinishLoading:self error:error];
- // }
- //
- // // NSURL *bundleURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]];
- // // [webView loadHTMLString:@"<html></html>" baseURL:bundleURL];
- //
- // [self.wkwebView.scrollView showEmpty];
- // }
- //}
- //
- //- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation
- //{
- // NSLog(@"%s",__func__);
- // @synchronized (self) {
- // if (self.hud) {
- // [self.hud dismiss];
- // self.hud = nil;
- // self.firstLoad = NO;
- // }
- //
- // if (self.delegate && [self.delegate respondsToSelector:@selector(webviewDidFinishLoading:error:)]) {
- // [self.delegate webviewDidFinishLoading:self error:nil];
- // }
- //
- // // self.wkwebView.scrollView.scrollEnabled = NO;
- // [webView evaluateJavaScript:@"document.body.scrollHeight" completionHandler:^(id result, NSError *_Nullable error) {
- //
- // NSLog(@"web page height:%@",result);
- // //result 就是加载完成后 webView的实际高度
- // //获取后返回重新布局
- //
- // }];
- // }
- //
- //
- //}
- //
- //- (void)webView:(WKWebView *)webView didCommitNavigation:(WKNavigation *)navigation {
- // NSLog(@"%s",__func__);
- //}
- //
- //- (void)webViewWebContentProcessDidTerminate:(WKWebView *)webView {
- // NSLog(@"%s",__func__);
- //}
- //
- //- (void)webView:(WKWebView *)webView decidePolicyForNavigationResponse:(WKNavigationResponse *)navigationResponse decisionHandler:(void (^)(WKNavigationResponsePolicy))decisionHandler
- //{
- // NSLog(@"%s",__func__);
- // decisionHandler(WKNavigationResponsePolicyAllow);
- //}
- @end
|