Skip to content

Instantly share code, notes, and snippets.

@iljaiwas
Created April 1, 2020 16:10
Show Gist options
  • Save iljaiwas/85b215b7da145795f925f435885c8e7c to your computer and use it in GitHub Desktop.
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
- (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