#import <Y3WebView.h>
This view simply sub-classes the WKWebView, to catch Copy/Paste and firstResponder notices.
Definition at line 18 of file Y3WebView.h.
◆ becomeFirstResponder()
- (BOOL) becomeFirstResponder |
|
|
|
|
implementation |
Definition at line 62 of file Y3WebView.m.
64 NSLog(
@"Y3WebView.becomeFirstResponder");
65 [y3rDelegate becomeResponder:YES];
66 BOOL ret = [
super becomeFirstResponder];
◆ copy:()
- (void) copy: |
|
(id) |
sender |
|
Definition at line 76 of file Y3WebView.m.
77 NSLog(
@"Y3WebView.copyClicked: start:sender class: %@", NSStringFromClass([sender
class]));
79 [
self exerciseJavascriptSendSelection];
◆ exerciseJavascriptBasic:()
- (void) exerciseJavascriptBasic: |
|
(NSString *) |
js |
|
|
implementation |
Definition at line 119 of file Y3WebView.m.
121 void (^queryCopyBlock)(id, NSError *error) = [
self provideQueryCopyBlock:ReturnBasic];
122 [
self evaluateJavaScript:js completionHandler:queryCopyBlock];
◆ exerciseJavascriptScanForIngredients()
- (void) exerciseJavascriptScanForIngredients |
|
|
|
|
implementation |
Definition at line 170 of file Y3WebView.m.
172 NSBundle *mb = [NSBundle mainBundle];
174 NSString *jsPathStr = [mb pathForResource:@"scanForIngredients"
176 inDirectory:@"webviewJS"];
177 NSString* content = [NSString stringWithContentsOfFile:jsPathStr
178 encoding:NSUTF8StringEncoding
181 NSLog(
@"Y3WebView.exerciseJavascriptScanForIngredients: content: %@", content);
182 void (^queryIngredientsCopyBlock)(id, NSError *error) = [
self provideQueryCopyBlock:ReturnIngredients];
183 [
self evaluateJavaScript:content completionHandler:queryIngredientsCopyBlock];
185 NSLog(
@"Y3WebView.exerciseJavascriptScanForIngredients: error: %@", error);
◆ exerciseJavascriptScanForInstruction()
- (void) exerciseJavascriptScanForInstruction |
|
|
|
|
implementation |
Definition at line 188 of file Y3WebView.m.
190 NSBundle *mb = [NSBundle mainBundle];
191 NSString *jsPathStr = [mb pathForResource:@"scanForInstruction"
193 inDirectory:@"webviewJS"];
194 NSString* content = [NSString stringWithContentsOfFile:jsPathStr
195 encoding:NSUTF8StringEncoding
197 void (^queryInstructionCopyBlock)(id, NSError *error) = [
self provideQueryCopyBlock:ReturnInstructions];
198 [
self evaluateJavaScript:content completionHandler:queryInstructionCopyBlock];
◆ exerciseJavascriptScanForRecipe()
- (void) exerciseJavascriptScanForRecipe |
|
|
|
|
implementation |
Definition at line 135 of file Y3WebView.m.
137 NSBundle *mb = [NSBundle mainBundle];
138 NSString *jsPathStr = [mb pathForResource:@"scanForRecipe"
140 inDirectory:@"webviewJS"];
141 NSString* content = [NSString stringWithContentsOfFile:jsPathStr
142 encoding:NSUTF8StringEncoding
144 NSLog(
@"Y3WebView.exerciseJavascriptScanForRecipe: content: %@", content);
145 void (^queryTitleCopyBlock)(id, NSError *error) = [
self provideQueryCopyBlock:ReturnTitle];
146 [
self evaluateJavaScript:content completionHandler:queryTitleCopyBlock];
◆ exerciseJavascriptScanForTitle()
- (void) exerciseJavascriptScanForTitle |
|
|
|
|
implementation |
Definition at line 156 of file Y3WebView.m.
158 NSBundle *mb = [NSBundle mainBundle];
159 NSString *jsPathStr = [mb pathForResource:@"scanForTitle"
161 inDirectory:@"webviewJS"];
162 NSString* content = [NSString stringWithContentsOfFile:jsPathStr
163 encoding:NSUTF8StringEncoding
165 NSLog(
@"Y3WebView.exerciseJavascriptScanForTitle: content: %@", content);
166 void (^queryTitleCopyBlock)(id, NSError *error) = [
self provideQueryCopyBlock:ReturnTitle];
167 [
self evaluateJavaScript:content completionHandler:queryTitleCopyBlock];
◆ exerciseJavascriptSendSelection()
- (void) exerciseJavascriptSendSelection |
|
|
|
|
implementation |
Definition at line 124 of file Y3WebView.m.
126 NSBundle *mb = [NSBundle mainBundle];
127 NSString *jsPathStr = [mb pathForResource:@"detectSelection"
129 NSString* content = [NSString stringWithContentsOfFile:jsPathStr
130 encoding:NSUTF8StringEncoding
133 [
self exerciseJavascriptBasic:content];
◆ initWithFrame:configuration:andControllerDelegate:()
- (instancetype) initWithFrame: |
|
(CGRect) |
frame |
configuration: |
|
(WKWebViewConfiguration *) |
configuration |
andControllerDelegate: |
|
(id<Y3WebViewDelegate>) |
delegate |
|
|
| |
Definition at line 41 of file Y3WebView.m.
42 configuration:(WKWebViewConfiguration *)configuration
43 andControllerDelegate:(id<Y3WebViewDelegate>)
delegate 45 self = [
super initWithFrame:frame configuration:configuration];
49 if (configuration.showConsole) {
50 WKUserContentController *userCC = configuration.userContentController;
51 [userCC addScriptMessageHandler:self name:@"log"];
53 [userCC addScriptMessageHandler:self name:@"logging"];
54 [userCC addScriptMessageHandler:self name:@"newSelectionDetected"] ;
id< Y3WebViewDelegate > y3rDelegate
id< U7ParamEditControlDelegate > delegate
◆ provideQueryCopyBlock:()
- (id NSError *error) provideQueryCopyBlock: |
|
(MenuItemSegment) |
itemSegment |
|
|
implementation |
Definition at line 82 of file Y3WebView.m.
82 :(MenuItemSegment) itemSegment
84 void (^queryCopyBlock)(id, NSError *error) = ^
void(
id jsReturn, NSError *error)
89 switch (itemSegment) {
91 [
self->y3rDelegate jsReturnIndication:jsReturn];
92 NSLog(
@"Y3WebView.provideQueryCopyBlock: ReturnBasic: %@", jsReturn);
95 [
self->y3rDelegate jsTitleReturn:jsReturn];
96 NSLog(
@"Y3WebView.provideQueryCopyBlock: ReturnTitle: %@", jsReturn);
98 case ReturnIngredients:
99 [
self->y3rDelegate jsIngredientsReturn:jsReturn];
100 NSLog(
@"Y3WebView.provideQueryCopyBlock: ReturnIngredients: %@", jsReturn);
102 case ReturnInstructions:
103 [
self->y3rDelegate jsInstructionReturn:jsReturn];
104 NSLog(
@"Y3WebView.provideQueryCopyBlock: ReturnInstructions: %@", jsReturn);
107 NSLog(
@"Y3WebView.provideQueryCopyBlock: default?: ret: %@", jsReturn);
110 [
self->y3rDelegate setControlbarColor:[UIColor greenColor]];
112 NSLog(
@"Y3WebView.provideQueryCopyBlock: completion: ERROR: %@", error);
113 [
self->y3rDelegate setControlbarColor:[UIColor redColor]];
116 return queryCopyBlock;
◆ resignFirstResponder()
- (BOOL) resignFirstResponder |
|
|
|
|
implementation |
Definition at line 69 of file Y3WebView.m.
71 NSLog(
@"Y3WebView.resignFirstResponder");
72 [y3rDelegate becomeResponder:NO];
73 BOOL ret = [
super resignFirstResponder];
◆ showConsole()
Definition at line 201 of file Y3WebView.m.
203 NSString *jsCode =
@"console.log = (function(oriLogFunc){\ 204 return function(str)\ 206 window.webkit.messageHandlers.log.postMessage(str);\ 207 oriLogFunc.call(console,str);\ 211 [
self.configuration.userContentController addUserScript:[[WKUserScript alloc] initWithSource:jsCode injectionTime:WKUserScriptInjectionTimeAtDocumentStart forMainFrameOnly:YES]];
◆ userContentController:didReceiveScriptMessage:()
- (void) userContentController: |
|
(WKUserContentController *) |
userContentController |
didReceiveScriptMessage: |
|
(WKScriptMessage *) |
message |
|
|
| |
|
implementation |
Definition at line 213 of file Y3WebView.m.
213 :(WKUserContentController *)userContentController didReceiveScriptMessage:(WKScriptMessage *)message {
214 NSLog(
@"OK> %@",message.body);
The documentation for this class was generated from the following files: