2
NSString* urlText = @"http://www2.htk.dk/Socialpsykiatrien/menuplan%20værestedet.pdf";
NSString* urlTextEscaped = [urlText stringByAddingPercentEscapesUsingEncoding:NSISOLatin1StringEncoding];
NSURL *url = [NSURL URLWithString: urlTextEscaped];

NSURLRequest *request = [NSURLRequest requestWithURL:url];

here's my code. and it stops at NSURLRequest each time... it looks like it loads the url correctly tho but i can't seem to find the error

all the console says is : (lldb)

4

1 回答 1

2

It works fine if you avoid percent escaping something that is already percent escaped:

NSString* urlText = @"http://www2.htk.dk/Socialpsykiatrien/menuplan værestedet.pdf";
NSString* urlTextEscaped = [urlText stringByAddingPercentEscapesUsingEncoding:NSISOLatin1StringEncoding];
NSURL *url = [NSURL URLWithString: urlTextEscaped];
NSURLRequest *request = [NSURLRequest requestWithURL:url];

Or, if your source for this string already has a %20 buried in it, you can unescape it and re-escape it:

NSString* urlText = @"http://www2.htk.dk/Socialpsykiatrien/menuplan%20værestedet.pdf";
NSString* urlTextUnescaped = [urlText stringByReplacingPercentEscapesUsingEncoding:NSISOLatin1StringEncoding];
NSString* urlTextEscaped = [urlTextUnescaped stringByAddingPercentEscapesUsingEncoding:NSISOLatin1StringEncoding];
NSURL *url = [NSURL URLWithString: urlTextEscaped];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
于 2013-11-04T21:08:05.337 回答