下载大量图像,速度更快
我需要从网络服务器下载的帮助...... 我目前所做的是从包含图像位置的网络服务器获取 XML 文件,解析 XML,下载每个图像,将图像存储在 iphone 上,并将图像名称存储到 sql 数据库。 这需要很多时间,因为需要下载大量图像,而且我正在一张一张地下载。
我的应用程序更新刚刚被拒绝,因为审阅者认为下载时间太长...有趣的是,最后两次更新都没有问题地通过了..
我正在考虑将这些图像压缩到服务器上并将 zip 文件发送到 iphone,在那里解压缩,或者将图像与二进制文件打包在一起并发送给苹果。
任何有关如何加快下载速度的建议,将不胜感激。谢谢。
I need help with downloading from webserver...
What i currently do is get XML file from web servers that contains image locations, parse XML, download each image, store image on iphone, and store image name to sql database.
This takes lots of time because there is large amount of images to be downloaded and i am downloading one by one.
My app update just got rejected because reviewer decieded that downloading is too long... What is funny, last two updates passed without problems..
I was thinking about zipping those images on server and sending zip file to iphone, unzipping it there, or packing images together with binary and sending it to apple.
Any advice on how to make download faster, would be appreciated. Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
顺便说一句,zip 对图像没有帮助。它们已经被压缩,因此只会增加开销。确保你的图像不大于显示所需的大小,我会按照 Mario 上面的建议进行操作,并在多个异步调用中下载它们(至少使一个大调用异步。)
UI 设计的一个关键原则是显示部分结果(除非它们无效或具有误导性),以便用户了解正在取得进展。
如果您确实需要所有图像才能使其有效,您可以下载一些图像并将它们显示为灰色(alpha = 0.4)或其他内容,以便清楚地表明这是部分结果,但正在取得进展。审稿人可能觉得启动时间太长了。
BTW, zip won't help with images. They are already compressed, so it will just add overhead. Make sure your images are not any larger than you need for display and I'd do what Mario suggested above and download them in multiple async calls (at least make the one big call asynchronous.)
A key principle of UI design is to display partial results (unless they are invalid or misleading) so that the user understands that progress is being made.
If you really need all the images to make it valid, you can download a few and display them grayed out (alpha = 0.4) or something so that it's clear that this is a partial result, but that progress is being made. The reviewer probably felt that it was taking too long to startup.
您经常更改这些图像吗?或者每个版本只发布一次(如果有的话)?如果它们随着每个版本的变化而变化,我只会将它们打包。如果它们几乎从未更改过,请进行一次大型下载(这样人们在更新时不必重新下载),如果它们经常更改,请逐个文件下载它们,但尝试使用一次下载 2-3 个文件异步下载(如果支持)。
Do you change those images often? Or only once per release if at all? If they change with each release only I'd package them. If they're almost never changed, go with the one huge download (so people don't have to redownload when updating) and if they're change often, download them file by file but try to do 2-3 files at once using asynchronous download (if supported).
1)我会使用 NSOperationQueue 之类的东西在后台一次下载大约三个图像。不仅如此,用户界面开始变得不稳定。
2) 在此过程中还显示某种加载指示器。
3)你的图片是什么格式的?如果您通过网络传输,则应使用 JPG,并考虑将质量级别设置为较小的值(例如 6 甚至 5)。为了抵消质量损失,您可以发送更大的图像,即使像素数量较多,您也可以通过较低质量的压缩轻松获得更好的效果。
4) 如果必须使用 PNG 来保持透明度,请考虑在发送之前对图像使用 PNGCrush。如前所述,zip 几乎不会执行任何操作。
1) I would use something like an NSOperationQueue to download around three images at a time in the background. Much more than that and the UI starts getting choppy.
2) Also display some kind of loading indicator while this is going on.
3) What format are your images in? If you are transferring over the network you should use JPG, and consider setting the quality level to something smaller (say 6 even 5). To offset the loss of quality you could send down larger images, even with the larger number of pixels you can easily be better off with a lower quality compression.
4) If you have to use PNG to preserve transparency, consider using PNGCrush on the images before sending. As noted, zip will do pretty much nothing.
加快这些图像下载速度的一种方法是将它们放在 CDN 上。有些 CDN(例如 Limelight)针对向移动设备发送数据进行了特殊的网络优化。它们还可以更好地路由内容,并且具有更高的内容传输能力。这种方法的好处是您可能不必更改您的应用程序。然而 CDN 可能很昂贵。
One way to speed up download of those images is to put them on a CDN. Some CDNs, like Limelight have special network optimizations for sending data to mobile devices. They also just do a better job of routing content, and have higher capacity for transmitting content. What's nice about this approach is that you might not have to change your app. However CDNs can be pricy.
您的图像可能太大了。您说您担心 20MB 的应用程序限制,但我认为在这一点上,您的图像对于手机来说太大了。
我很确定您需要缩小图像的大小,而不是压缩文件。不仅如此,您还应该只在需要时下载您需要的内容。
如果您仍然想要批量下载,为什么不将其作为辅助选项而不是默认实现呢?
Likely, your images are just way too large. You said you're worried about the 20MB app limit, but I think at that point, your images are just way too large for the phone.
Rather than zipping the files, I'm pretty sure you need to downsample the size of the images. Not only that, but you should only download the ones that you need, when you need them.
If you still want to have bulk downloads, why not have it as a side option rather than the default implementation?