0

In the server side, there would be many text and images that I want to download. The question is I do not want to get those things separately, I would like to pack them into a single file, so that it is easier to utilize pause-and-resume capability. Should I zip them in server side and unzip the file in mobile side? Is there any API that I can use to unzip in mobile side?

I am not sure about if my idea is correct or not. Is this the common way of doing this sort of things? Thank you.

Rob
  • 415,655
  • 72
  • 787
  • 1,044
user2053760
  • 1,673
  • 2
  • 14
  • 19

1 Answers1

0

Regarding the images, frequently we download them individually, and merely update the UI as stuff is downloaded, rather than forcing the user to wait for everything to download. Or lazy downloads are nice (such as afforded by UIImageView category, like SDWebImage's UIImageView+WebCache), effectively downloading the images as they're needed, that way the user can use the app without needing to wait for everything to download.

Regarding the text, unless they're huge, you can download them together. Rather than zipping a bunch of text files, though, I think post people would be inclined towards some JSON-formatted response that returns the text files in some nice, easy to consume format by your app. There's a point (say, the combined JSON is more than 100k), though, where combining the text files together hits a point of diminishing returns, in which case you might want to pursue individual downloads.

We need more background on what the app does and the breakdown of data (how big are the individual text files, how many, etc.) before providing meaningful counsel. But unless there absolutely no way for the app to function at all until everything is downloaded, I'd be inclined towards separate downloads for images, and some nice JSON-format single feed for the text.

Let's assume for a second that you have some text description of a series of products, an an image associated with each. Then you might have a JSON that looks like:

[
    {
        "id": 1,
        "description": "This product is ...",
        "image_url": "http://www.yourserver.com/images/img001.png"
    },
    {
        "id": 2,
        "description": "This different product is ...",
        "image_url": "http://www.yourserver.com/images/img002.png"
    },
    {
        "id": 3,
        "description": "This third product is ...",
        "image_url": "http://www.yourserver.com/images/img003.png"
    },
    {
        "id": 4,
        "description": "This last product is ...",
        "image_url": "http://www.yourserver.com/images/img004.png"
    }
]

Your app might download that JSON (in which case it would have all of the text strings and a bunch of image URLs), and then present that in the UI, and where it needs to display the image, use the UIImageView category of SDWebImage to update the image of the UIImageView like so:

[cell.imageView setImageWithURL:[NSURL URLWithString:imageUrlString]
               placeholderImage:[UIImage imageNamed:@"placeholder.png"]];
Rob
  • 415,655
  • 72
  • 787
  • 1,044
  • I have used SDWebImage. My question is like this: Say my app is a online magzine viewer. Users can read E-magzine online, so that SDWebImage can be useful. However, I would like to provide a functionality to enable download of the magazine. Once it is downloaded, users can read them offline. So the problem is how I am supposed to handle this. I am thinking of wrapped the texts and images of a magazine to a zip file, and users can just download that file, and in mobile side, my app unzip it and save data to relative database tables. Is this the right way of doing this? – user2053760 Oct 20 '13 at 17:23
  • I've seen both the download-whole-edition-first model (lots of magazines do this) as well as retrieve-as-you-go-and-optionally-retrieve-everything-for-offline model (a bunch of newspapers do this). I think the latter is more elegant, but the former is obviously easier. In terms of zip libraries, see [this question](http://stackoverflow.com/questions/11333399/download-and-unzip-file-in-ios). – Rob Oct 20 '13 at 21:04