Reputation: 141
I have a web view displaying many images from any URL. When I click or longpress on particular image I need to download that image data . How is it possible?
Upvotes: 0
Views: 1119
Reputation: 1564
A simple solution would be to keep listening to the UIWebview
delegate, shouldStartLoadWithRequest
and whenever the URL ends with a .jpg or .png, you could stop the redirection and download the image manually.
NSData *data = [NSData dataWithContentsOfURL:url];
UIImage *img = [UIImage imageWithData:data];
A more complex approach would be to use javascript and detect the point(x,y) of the touch on the UIWebview
and then find corresponding element tag. If the element is an image, you then do a image download using the above method. But this is complicated and i'm not entirely sure if this can be achieve. If the first approach doesn't help you then this is worth a shot, if you ask me.
You should put a gesture recogniser UILongPressGestureRecognizer
and add a listener. So you could then call your java script function from there instead of doing it from the touches delegate method.
Upvotes: 1