I have super simple code that downloads an image from the web. It was working fine in iOS 8 but now I keep getting this error now in Xcode 7.3 with iOS 9. Is this a bug?
NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask ,YES);
NSString* documentsPath = [paths objectAtIndex:0];
NSError *error;
NSString *data2URL = @"http://cdn.minecraftpocket-servers.com/images/flags/Brazil.png";
NSURL *url = [NSURL URLWithString:data2URL];
NSString *imgFileNameStr = [data2URL lastPathComponent];
NSData *data2 = [NSData dataWithContentsOfURL:url options: NSDataReadingUncached error: &error];
if (error)
NSLog(@"Download error: %@",error);
//check
if (data2 == NULL)
{
NSLog(@"DATA IS NULL");
}
else
{
NSLog(@"DATA IS NOT NULL");
}
//saving file
NSString* fullPathToFile2 = [documentsPath stringByAppendingPathComponent:imgFileNameStr];
BOOL success = [data2 writeToFile:fullPathToFile2 atomically:NO];
NSLog(@"Success = %d ...", success);
ERROR:
2016-07-03 23:00:36.963 014-test-proj[15404:419151] Download error: Error Domain=NSCocoaErrorDomain Code=256 "The file “Brazil.png” couldn’t be opened." UserInfo={NSURL=http://cdn.minecraftpocket-servers.com/images/flags/Brazil.png}
2016-07-03 23:00:36.963 014-test-proj[15404:419151] DATA IS NULL
2016-07-03 23:00:36.964 014-test-proj[15404:419151] Success = 0 ...
I have already checked & made sure of my plist file for application security.
Someone had the same problem HERE. What did I miss?
UPDATE: Code works if I use this link ...
NSString *data2URL =@"https://upload.wikimedia.org/wikipedia/commons/1/1e/Large_Siamese_cat_tosses_a_mouse.jpg";
I don't get it. Why would it have an issue with the other one.