我的服务器上有一些图像,以特殊字符 (å,ä,ö) 命名。我不知道如何转换 NSUrl 来获取它们:
NSString *urlString = [NSString stringWithFormat: @".../Images/%@Image.png", playerName];
NSURL *url = [NSURL URLWithString: [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSLog(@"url:%@", url);
//Get the image and assign it to the player
NSData *imageData = [NSData dataWithContentsOfURL:url];
UIImage *image = [UIImage imageWithData:imageData];
上例中的日志(如果“playerName”=åäö):
.../Images/%C3%A5%C3%A4%C3%B6Image.png
但我需要它是:
.../Images/åäöImage.png
我尝试了不同的(stringByAddingPercentEscapesUsingEncoding)和下面的代码但没有成功:
- (NSString *)URLEncodingOfString:(NSString *)s
{
return (__bridge NSString *)CFURLCreateStringByAddingPercentEscapes
(kCFAllocatorDefault, (__bridge CFStringRef)s, NULL, NULL,
kCFStringEncodingISOLatin1);
}
非常感谢任何建议,在此先感谢