Created
April 1, 2020 16:10
-
-
Save iljaiwas/85b215b7da145795f925f435885c8e7c to your computer and use it in GitHub Desktop.
Getting hold of the image data inserted into your WebView by Apple's Continuity Camera feature
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (BOOL)webView:(WebView *)inWebView shouldInsertNode:(DOMNode *)node replacingDOMRange:(DOMRange *)range givenAction:(WebViewInsertAction)action | |
{ | |
if (WebViewInsertActionPasted == action) { | |
if ([node isKindOfClass:DOMDocumentFragment.class]) { | |
DOMDocumentFragment *frag = (DOMDocumentFragment*) node; | |
if ([[frag childNodes] length] == 1) { | |
DOMNode *firstChildNode = [[node childNodes] item:0]; | |
if ([firstChildNode isKindOfClass:DOMHTMLImageElement.class]) { | |
DOMHTMLImageElement *imageElement = (DOMHTMLImageElement*) firstChildNode; | |
NSURL *imageURL = [imageElement absoluteImageURL]; | |
WebResource *imageResource = [inWebView.mainFrame.dataSource subresourceForURL:imageURL]; | |
NSData *imageData = [imageResource data]; | |
// Now do something with your image data | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment