I want to take a screenshot and then send to webview a local path for it, so it will show it. I know that webview could take images from NSBundle but this screenshots are created dynamically - can I add something to it by code?
I was trying it like this:
UIGraphicsBeginImageContext( webView.bounds.size);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSString *file = @"myfile.png";
NSString *directory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES) objectAtIndex:0];
NSString *path = [directory stringByAppendingPathComponent: file];
[UIImagePNGRepresentation(viewImage) writeToFile:path atomically:YES];
NSString *function = [NSString stringWithFormat:@"loadImagePlease(%@);",path];
[ ad stringByEvaluatingJavaScriptFromString:function];
But loadImageFunction can't access it , with file:/// or file:// prefix. What's the solution? Thanks for ANY help.
EDIT: added a missing line in code
SOLUTION: I used a Cyrille's advice and this library for encoding : http://cocoawithlove.com/2009/06/base64-encoding-options-on-mac-and.html