简体   繁体   中英

IOS download multiple files

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.

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"]];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM