So my basic problem is, I have a webview containing simple code like

<img src="fixedname.jpg">

Now I need to set the baseurl so the webview can find the image, but my image is dynamically created, let's assume I have just the byte data in a NSData object, how can I add a filename to it or create a NSURL which I can provide the webview?

Regards

有帮助吗?

解决方案

you may try to save image into local file and set the url of file instead of image name in web view. try the following
NSData* data = UIImagePNGRepresentation(yourDynamicImage);

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

NSString *documentDirectory = [paths objectAtIndex:0];
NSString* file= [documentDirectory stringByAppendingPathComponent:@"image.png"];
[data writeToURL:[NSURL URLWithString:file] atomically:YES];
NSURL url = [NSURL fileURLWithPath:file];

// pass the [url absoluteString] to the web view this should work

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top