1

I'm trying to get an image from a local url using AFNetworking with this code:

    NSString *path = [DOCUMENTS stringByAppendingPathComponent:[NSString stringWithString:@"My Image.png"]];
    [cell.imageView setImageWithURLRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:path]] placeholderImage:[UIImage imageNamed:@"Placeholder Image.png"] success:nil failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error) {
        NSLog(@"%s: setImageWithURLRequest error: %@", __FUNCTION__, error);
    }];

and I am getting this error:

NSErrorFailingURLKey=/var/mobile/Applications/6D878789-640E-4299-AA72-45D49211492D/Documents/My Image.png, NSLocalizedDescription=unsupported URL, NSUnderlyingError=0x15df8b60 "unsupported URL"}

How can I do this with AFNetworking?

Kara
  • 6,115
  • 16
  • 50
  • 57

2 Answers2

0

Try not setting the success block to nil and use this code:

[cell.myImage setImageWithURLRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"url"]] placeholderImage:nil success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image) 
{
            weakimageView.image = image;

          } failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error)
          {
             //Deal with failure
          }];
Shaik Riyaz
  • 11,204
  • 7
  • 53
  • 70
Segev
  • 19,035
  • 12
  • 80
  • 152
0

Try this it works perfectly fine,..

Download UIImageView+webcache.h and .m file and add to your project.

link is here https://github.com/rs/SDWebImage/blob/master/SDWebImage/UIImageView%2BWebCache.h

NSString *path = [DOCUMENTS stringByAppendingPathComponent:[NSString stringWithString:@"My Image.png"]];

[cell.imageView setImageWithURL:[NSURLRequest requestWithURL:[NSURL URLWithString:path]] placeholderImage:[UIImage imageNamed:@"Placeholder Image.png"]];

or using Blocks,

NSString *path = [DOCUMENTS stringByAppendingPathComponent:[NSString stringWithString:@"My Image.png"]];

[cell.imageView setImageWithURL:[NSURLRequest requestWithURL:[NSURL URLWithString:path]]  placeholderImage:[UIImage imageNamed:@"Placeholder Image.png"] success:^(UIImage *image, BOOL cached) {
        <#code#>  ---> if success
    } failure:^(NSError *error) {
        <#code#>  ---> if failure
    }];
Maniganda saravanan
  • 2,188
  • 1
  • 19
  • 35