Frage

I have an image at a URL which is failing to load into an NSData.

When I paste the image URL into a Chrome incognito window, it displays successfully.

However, the following fails:

photoData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:photoUrl]];
NSLog(@"data: %@", photoData);

The NSLog outputs:

data: (null)

Am I doing something wrong? I'd appreciate any advice, thanks.

Edit: The URL has extended ASCII characters in it, such as à.

War es hilfreich?

Lösung

Ugh. Found the answer. Needed to escape the URL for extended ASCII. Need to add:

photoUrl = [photoUrl stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding];

Found the answer here. Thanks!

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top