Why does NSData stay nil after loading from a valid url?
@interface ViewController : UIViewController
{
__strong IBOutlet UIImageView *testImageView;
}
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
NSData *imageData = [[NSData alloc] initWithContentsOfURL: [NSURL URLWithString: @"http://news.bbcimg.co.uk/media/images/79790000/jpg/_79790768_hi024951574.jpg"]];
// imageData => nil ???
testImageView = [[UIImageView alloc] initWithImage:[UIImage imageWithData: imageData]];
}
@end
I don't understand why it imageData
stays at zero even though the url exists. Is it because I am doing it from a simulator? Thanks to
UPDATE:
Not really sure why I am getting NSFileReadUnknownError = 256
source to share
After trying the code you provided, I have no problem showing the image.
It looks like the problem lies with your local network environment.
I know this may sound silly, but I recommend you reset and reload the iOS simulator . I experienced a bug that prevents the simulator from connecting correctly after sleeping and waking up the Mac . Xcode 6.1, Yosemite.
Also, check if you are connected via a proxy or if your file is /etc/hosts
understandable regarding the bbcimg.co.uk domain. Just a common common sense test.
source to share