Frage

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

War es hilfreich?

Lösung

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

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top