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
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.
When you are dealing with web services, you need permissions to carry arbitrary load. JUST do the following: 1. Go to p.list> rightClick> OpenAs> SourceCode 2. Paste the following lines into our p.list source code: (Find in the attached image)
3. Run the program and run it.