103 - (void)viewDidLoad {
106 CGRect totalFrame =
self.view.frame;
107 CGRect topNaviFrame = [[[
self navigationController] navigationBar] frame];
108 float availableWindowTop = topNaviFrame.origin.y + topNaviFrame.size.height;
111 CGRect webViewFrame = CGRectMake(8,
112 availableWindowTop + 4,
113 totalFrame.size.width - 16,
114 totalFrame.size.height - availableWindowTop - 8);
119 webPanel = [[
Y3WebView alloc] initWithFrame:webViewFrame andDelegate:self];
122 [
self.view addSubview:webPanel];
124 NSURL *nsurl=[NSURL URLWithString:@"http://google.com"];
125 NSURLRequest *nsrequest=[NSURLRequest requestWithURL:nsurl];
126 [webPanel.webView loadRequest:nsrequest];
131 -(void) viewWillAppear:(BOOL)animated
133 [webPanel.webView setBackgroundColor:[UIColor grayColor]];
134 [webPanel setBackgroundColor:[UIColor colorWithHue:0.22 saturation:1.0 brightness:0.6 alpha:1.0]];
136 - (void) userContentController:(WKUserContentController*)userContentController
137 didReceiveScriptMessage:(WKScriptMessage*)message
140 NSLog(
@"U4WebViewControler.userContentController-didReceiveScriptMessage");
141 if ([message.body isKindOfClass:[NSString
class]])
143 NSLog(
@"U4WebViewControler.userContentController: string");
147 - (void) becomeResponder:(BOOL) flag
149 [webPanel becomeResponder:flag];
150 [
self.view setNeedsLayout];
151 [
self.view setNeedsDisplay];
153 [
self.view snapshotViewAfterScreenUpdates:YES];
156 - (BOOL) jsReturnIndication:(NSString *)string
162 [webPanel.webControls setBackgroundColor:[UIColor greenColor]];
166 [webPanel.webControls setBackgroundColor:[UIColor orangeColor]];
171 - (void) jsTitleReturn:(NSString *)string
173 NSLog(
@"U4WebViewController.jsTitleReturn: string: %@",
string);
174 if ([
self jsReturnIndication:
string]) {
178 - (void) jsIngredientsReturn:(NSString *)string
180 if ([
self jsReturnIndication:
string]) {
184 - (void) jsInstructionReturn:(NSString *)string
186 if ([
self jsReturnIndication:
string]) {
193 NSString *displayString =
@"WEB COPY";
194 NSArray<NSString *> *pasteStrings = [[UIPasteboard generalPasteboard] pasteboardTypes];
196 for (NSString *pasteStr in pasteStrings) {
198 NSObject *valPasteType = [pasteboard valueForPasteboardType:pasteStr];
199 if (nil != valPasteType) {
200 NSLog(
@"U4WebViewController.logCopy: has paste type: %@", pasteStr);
202 NSString *addPasteType = [NSString stringWithFormat: @"%@ - %@", @"\n", pasteStr];
203 displayString = [displayString stringByAppendingString:addPasteType];
205 if ([
@"public.utf8-plain-text" isEqualToString:pasteStr]) {
206 NSObject *obj5 = [pasteboard valueForPasteboardType:pasteStr];
207 NSString *addInfo = [NSString stringWithFormat: @"%@", obj5];
208 displayString = [displayString stringByAppendingString:addInfo];
212 NSLog(
@"U4WebViewController.logCopy: displayString: %@", displayString);
214 - (void) setControlbarColor:(UIColor *)color
216 [webPanel.webControls setBackgroundColor:color];
219 - (void) fireSnippetScreen
221 NSLog(
@"U4WebViewController.fireSnippetScreen: w/title: %@",
mostRecentTitle);
225 [parameterView setShowHtmlTitle:mostRecentTitle];
227 NSAttributedString *titleSimple = [[NSAttributedString alloc] initWithData:[mostRecentTitle dataUsingEncoding:NSUTF8StringEncoding] options:@{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType, NSCharacterEncodingDocumentAttribute: [NSNumber numberWithInt:NSUTF8StringEncoding]} documentAttributes:nil error:nil];
228 [parameterView setShowTextTitle:[titleSimple string]];
231 [parameterView setShowHtmlIngredients:mostRecentIngredients];
232 [parameterView setShowHtmlInstruction:mostRecentInstruction];
234 [
self.navigationController pushViewController:parameterView animated:YES];
236 #pragma mark - WKUIDelegate 238 - (void)
webView:(WKWebView *)webView2 didFinishNavigation:(WKNavigation *)navigation
240 [webPanel updateWebControls];
241 [webPanel.webControls setBackgroundColor:[UIColor blueColor]];
242 [webPanel scanPageForTitle];
243 [webPanel scanPageForIngredients];
244 [webPanel scanPageForInstruction];
245 NSLog(
@"WebViewController.didFinishNavigation");
249 runJavaScriptAlertPanelWithMessage:(NSString *)message
250 initiatedByFrame:(WKFrameInfo *)frame
251 completionHandler:(
void (^)(
void))completionHandler
253 NSLog(
@"U4WebViewController:runJavaScriptAlertPanelWithMessage");
257 runJavaScriptConfirmPanelWithMessage:(NSString *)message
258 initiatedByFrame:(WKFrameInfo *)frame
259 completionHandler:(
void (^)(BOOL result))completionHandler
261 NSLog(
@"U4WebViewController:runJavaScriptConfirmPanelWithMessage");
266 runJavaScriptTextInputPanelWithPrompt:(NSString *)prompt
267 defaultText:(NSString *)defaultText
268 initiatedByFrame:(WKFrameInfo *)frame
269 completionHandler:(
void (^)(NSString *result))completionHandler
271 NSLog(
@"U4WebViewController:runJavaScriptTextInputPanelWithPrompt");
275 #pragma mark - WKNavigationDelegate 278 didCommitNavigation:(WKNavigation *)navigation
283 - (void)
webView:(WKWebView *)webView didStartProvisionalNavigation:(null_unspecified WKNavigation *)navigation
285 NSLog(
@"U4WebViewController.didStartProvisionalNavigation: active URL: %@",
webView.URL.description);
286 [webPanel.webControls setBackgroundColor:[UIColor whiteColor]];
289 - (void)
webView:(WKWebView *)webView decidePolicyForNavigationResponse:(WKNavigationResponse *)navigationResponse decisionHandler:(
void (^)(WKNavigationResponsePolicy))decisionHandler{
290 NSHTTPURLResponse *response = (NSHTTPURLResponse *)navigationResponse.response;
291 NSArray *cookies =[NSHTTPCookie cookiesWithResponseHeaderFields:[response allHeaderFields] forURL:response.URL];
292 for (NSHTTPCookie *cookie in cookies) {
293 [[NSHTTPCookieStorage sharedHTTPCookieStorage] setCookie:cookie];
296 decisionHandler(WKNavigationResponsePolicyAllow);
302 - (void)
webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(
void (^)(WKNavigationActionPolicy))decisionHandler {
304 NSURLRequest *request = navigationAction.request;
314 if (navigationAction.navigationType == WKNavigationTypeLinkActivated) {
351 if (decisionHandler) {
352 decisionHandler(WKNavigationActionPolicyAllow);
356 #pragma mark - controls 414 - (void)didReceiveMemoryWarning {
415 [
super didReceiveMemoryWarning];
417 NSLog(
@"U4WebViewController.didReceiveMemoryWarning");
NSString * mostRecentJavascriptReturnStr
UIPasteboard * pasteboard
NSString * mostRecentTitle
NSString * mostRecentIngredients
NSString * mostRecentInstruction