我正在将图像加载到 iPhone 上的图库中,但遇到了问题。显然,当尝试从互联网下载图像时,脚本中的某些内容对文件名中的空格不满意。
这是连接线。
NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:str]] delegate:self];
我在 NSURL 中传递了一个 NSString。它适用于所有没有空格的照片。
邪恶照片示例:
拇指_WJ (16).jpg
拇指_WJ (25).jpg
现在我知道我可以返回并更新所有照片、更新数据库并更改脚本,这样就不再添加空格...但我们正在谈论数千张照片。
和建议?
I am working on loading images into a gallery on the iPhone and running into an issue. It is apparent that something in the script isn't happy with spaces being in filename's when trying to download the images off of the internet.
This is the connection line.
NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:str]] delegate:self];
And I pass an NSString in the NSURL. It works on all photos that don't have spaces.
Example of evil photos:
thumbs_WJ (16).jpg
thumbs_WJ (25).jpg
Now I know I could go back and update all the photos, update the database, and change the script so it doesn't add spaces anymore...but we are talking about thousands of photos.
And suggestions?
发布评论
评论(3)
你需要做字符串:
you need to do string:
对要作为参数包含的文本使用
NSString
的stringByAddingPercentEscapesUsingEncoding:
方法。来自 Apple 文档:
如果您的字符串是“普通”字符串,则可以使用
NSUTF8StringEncoding
作为编码。否则,请指定字符串所在的编码。Use
NSString
'sstringByAddingPercentEscapesUsingEncoding:
method on the text you want to include as an argument.From Apple docs:
If your string is a "normal" string, you can use
NSUTF8StringEncoding
as encoding. Otherwise, specify the encoding your string is in.只需将 URL 字符串中的空格替换为“%20”即可。
Just replace spaces with "%20" in your urlstring.