0

i am parsing json from SBJson parser. I am using SDWebIamge for image caching. My JSON data has one tag namely "content" which has text + image links in between text. Just for example something like this

<p>This is sample text.<\/p>\n<p><a href=\"http:\/\/xyz.com\/08\/15.jpg\"><img class=\"aligncenter size-full wp-image-1273\" title=\"15\" src=\"http:\/\/xyz.com\/08\/15.jpg\" alt=\"\" width=\"422\" height=\"720\" \/><\/a><\/p>\n<p><a href=\"http:\/\/xyz.com\/08\/16.jpg\"><img class=\"aligncenter size-full wp-image-1274\" title=\"16\" src=\"http:\/\/xyz.com\/08\/16.jpg\" alt=\"\" width=\"680\" height=\"1024\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n

which i parse and store in my NSString variable.Then i have a webview which i load from this NSString by

 NSString *htmlString = [[NSString alloc] initWithString:myObj.Content];

which loads the text and fetches link images as well by default as we all know web view does.I am saving this JSON data to file for offline viewing which is working great thanks to SDWebimage.But my issue is when i load the save content to webview it shows only text no image cause these is no image cashing in the NSString links which i loaded.So how can i cache the images in my webview so that next time when i load my webview from string it will show images from the link in my NSString data.

Thanks

Rishi
  • 3,499
  • 8
  • 35
  • 54

1 Answers1

0

You can use an existing implementation to do this - something like ASIWebPageRequest or ProxyingUIWebView should to the trick.

Alternatively you could try to implement this yourself. One option is something like the following:

  1. Parse the HTML string and detect any img tags and their src attributes
  2. Download and store any images detected
  3. Display the stored (downloaded images) in place of the online originals by modifying the path to the images in the img tags in your HTML string.

Note this is a far from optimal solution and is only an example of one possible implementation.

jstr
  • 1,271
  • 10
  • 17