My purpose is trying to get the size of the downloaded image via the successful block like below:
[imageView setImageWithURLRequest:[NSURL URLWithString:((ObjectA*)obj[indexPath.row]).imageUrl]
placeholderImage:nil
success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image) {
CGFloat imageHeight = image.size.height;
CGFloat imageWidth = image.size.width;
NSLog(@"width of image is %f",imageWidth);
NSLog(@"height of image is %f",imageHeight);
}
failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error) {
;
} ];
However, I am getting a crash with shown error like below :
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSURL cachePolicy]: unrecognized selector sent to instance 0x1edb9e70'
Does anybody know the reason for this error. Please help if you have any ideas
The error is telling you that cachePolicy
(which is an NSURLRequest
method) is being called on an NSURL
object.
The problem is that you are passing in an NSURL
object as the first parameter instead of an NSURLRequest
object. (I'm not familiar with this 3rd party API, but the documentation appears to be here)
Issue is with this code:
[imageView setImageWithURLRequest:[NSURL URLWithString:((ObjectA*)obj[indexPath.row]).imageUrl]
The parameter of setImageWithURLRequest:
is NSURLRequest
, you are passing NSURL
. That's why it is crashing.
Change it to:
[imageViewsetImageWithURLRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:((ObjectA*)obj[indexPath.row]).imageUrl]]
I guess the problem is in the first line
[imageView setImageWithURLRequest:[NSURL URLWithString:imageUrl]
setImageWithURLRequest
from the signature looks like expecting a "URLRequest" whereas you are passing a URL.
So create a URLRequest
with the URL
and pass it and see if it is working
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With