Implementing hot updates for resource files such as iOS pictures (v): A simple and complete resource Hot Update page

Source: Internet
Author: User
Tags file url

Brief introduction

A simple about page, with a picture, version number, app name, etc., highlighting the complete integration examples for each series of articles.

Motivation and Meaning

This is the last of a series of articles. Take the time to write down today. The article itself will be on the basis of the fourth, a simple extension of the code, to achieve online download and reset the change function.

If you can read the first four articles in more detail, the example given in the fifth article should be understood as insignificant. But most of the time, we probably just need a simple solution, the kind of stuff that we can use to get it. That's the kind of scenario where we need to see a brief example of how the effect can be solved before we continue reading. So, for a long time, for a variety of reasons by the search engine or other article links directed to this series of people, they may want to see a brief example, to determine the series of articles, Whether or not they still make sense at that point in time.

As of now, my position on the blog record itself is still a tool of thought. When you see this article, maybe you're already using Xcode9 Xcode10, and maybe the code example is not running. But I believe that the reference links and some of the thoughts that are revealed in each article may still be enlightening to you.

Thinking and realization
    1. App version and name, can be read directly;
    2. Download Update resources online, you can use the code of the previous article to achieve;
    3. Reset, you can choose to clear the patch information or directly remove the patch, the first choice of this article;
Core code:

I need to extend the method of updating resources first, so that after the update is complete, I can return the results of the update so that I may do further work, such as displaying a picture again:

+ (void) Yf_updatepatchfrom: (NSString *) pathinfourlstr Completionhandler: (void (^) (BOOL success, Nserror * error))            completionhandler{if (! Completionhandler) {Completionhandler = ^ (BOOL success, Nserror * error) {    Nothing to do ...};           } [Self Yf_fetchpatchinfo:pathinfourlstr completionhandler:^ (nsdictionary *patchinfo, Nserror *error) {               if (Error) {NSLog (@ "Fetchpatchinfo error:%@", error);               Completionhandler (NO, error);           Return           } NSString * Urlstr = [Patchinfo objectforkey: @ "url"];           NSString * MD5 = [patchinfo objectforkey:@ "MD5"]; NSString * ORIMD5 = [[[Nsuserdefaults Standarduserdefaults] Objectforkey: [self Yf_sourcepatchkey]] objectforkey:@ "MD5"           ];               if ([OriMd5 isequaltostring:md5]) {//No update completionhandler (YES,NIL);           Return } [Self Yf_downloadfilefrom:urlstr completionhandler:^ (nsurl *location, Nserror *error) {if (error) {NSLog (@ "Download file url:%@ Error:%@", Urlst                   R, error);                   Completionhandler (NO, error);               Return               } NSString * Patchcachepath = [self yf_cachepathfor:md5]; [Ssziparchive unzipFileAtPath:location.path todestination:patchcachepath overwrite:yes password:nil error:&               ERROR];                   if (Error) {NSLog (@ "Unzip and move file error, with urlstr:%@ error:%@", URLSTR, error);                   Completionhandler (NO, error);               Return }/* Update patch info.               */NSString * Source_patch_key = [self yf_sourcepatchkey];               [[Nsuserdefaults Standarduserdefaults] Setobject:patchinfo Forkey:source_patch_key];           Completionhandler (Yes,nil);       }]; }];}

Then there is a customized online update for the click Method:

-(Ibaction) Onlineupdate: (ID) Sender {    __weak viewcontroller * weakself = self;    [UIImage yf_updatepatchfrom:@] Https://raw.githubusercontent.com/ios122/ios_assets_hot_update/master/res/patch_ 04.json "completionhandler:^ (BOOL success, Nserror *error) {        UIImage * image = [UIImage yf_imagenamed:@" Sub/sample "] ;        WeakSelf.sampleImageView.image = image;    }];}

A custom reset method is also required, taking into account future extensibility and current needs to support the results of block outgoing operations:

+ (void) Yf_reset: (void (^) (BOOL success, Nserror * error)) completionhandler{    if (! Completionhandler) {        complet Ionhandler = ^ (BOOL success, Nserror * error) {            //Nothing to do ...        };    }    [[Nsuserdefaults Standarduserdefaults] Setobject:nil forkey: [self yf_sourcepatchkey]];    Completionhandler (YES, nil);}

Specifically used, it is very simple, after resetting, the update tablet can:

-(ibaction) Reset: (ID) Sender {    __weak viewcontroller * weakself = self;    [UIImage yf_reset:^ (BOOL success, Nserror *error) {        if (success) {            UIImage * image = [UIImage yf_imagenamed:@ "Sub/sample"];            WeakSelf.sampleImageView.image = image;        } else        {            NSLog (@ "Reset error:%@", error);        }    ];}

Series of Articles Tips summary

This is the second series of articles. " We should believe that most people have the ability to appreciate good things "-if we can agree on this point, what I say below may be worth reading:

Some data
    • Open source China has recommended 2 blogs: four series of articles published, two in the OSC to get a small series of recommendations for the whole site.
    • Pinterest home Page recommended two, won a reward: the technical properties of the book itself, may not be very strong, but the recent search for technical information, there are many links to simple books, and the information is very timely and very fresh, the reason is unknown, so recently I also began to synchronize in the book update, as to receive prizes, In fact, only 2 yuan of spicy money, but it is obvious that this child shoes is to search for a message, was directed to my article, and from its comments, indeed to its certain help-I think, can be needed to see, this is the most let Bo master happy thing!
    • Weibo-related blog posts have 3-bit large V-forwards: In a way, I think it's a recognition. However, I do not really play micro-blog, but the information is too easy to drown, but if only to consider the dissemination of properties, micro-bo diffusion effect is actually very good.
    • Segmentfault the article to the headline, was Segmentfault's CEO Gaoyang Sunny two times, Weibo forwarded once. I felt flattered, but then I thought maybe people were just trying to push the new "headline" feature a little bit more.
    • CSDN Homepage Recommended once: The original notice is, "Your implementation of iOS pictures and other resources file Hot update (four): A minimal patch update logic is recommended to the homepage!" "This is really worth remembering!" At the beginning, I sent an article, if there is an outside chain, CSDN must be reviewed before it can be publicly seen!
Some experience
    • Work first, blog share second: I do not expect to be able to earn money by blogging in the future, that means that work must always be a priority. So, the blog update time is not really fixed. And there is, do not want the blog to share itself become a burden, if there is no mood or life has other things, I'll just put it in there and write it later.
    • Do not be bound by previous themes, write what you really need or really interested in: this series, in terms of time, is indeed one months behind the expected week, but from a practical point of view, it is much better than the previous spark series. But when I decided on the content of this series, I was very tangled, is to continue the spark big Data theme, or share their own have been wanting to study deeply, but has not been out of time resource package optimization problem. Ultimately, the latter is chosen because the current scenario for Spark does not have much to do with your work.
    • Recording ideas and reference resources may be more important than the solution itself: more than reading the experience of other people's blogs, the likelihood of encountering a fully consistent problem is small, and in many cases, it is found in the reference to the more detailed references to similar issues in the Blogger's reference, and, in addition, various citation sources, May also give a person a very tall feeling.
    • You'll need more time than you expected: you think that a half-hour-long article might take two hours to settle down; you think a technical point of a simple answer, in some detail, may be more experienced than you might think. When you realize that what you're doing is going to be read and appreciated in public. , you will be tempted to do a little more, look more, more optimization, do not want to appear too low.
Small plan
    • Theme, adhere to the series of articles: I found a series of articles, really conducive to help themselves carry out and adhere to deep and orderly thinking.
    • Theme, identified as mobile hybrid development: I've been developing apps with reactnative for the last year, but simply using them has not been enough for me, and I want to delve into some of the implementation mechanisms inside. As a comparison, we will study the community-driven Weex; will also focus on the domestic business-driven Apicloud platform.
    • The content involves IOS,ANDROID,HTML5 and automation scripts: iOS is a job, Android and HTML are the skills they need to fill, and the ability to write automated scripts will largely determine their ability to automatically handle complex information and future development- It is said that Lisp is the first language in the universe, but it is still a relatively basic shell script.
    • Articles and comments should only talk about technology: Reactnative represents the direction of the mixed development, to a certain extent, has been the domestic bat as the representative of the first-line technology companies, we can go to the showcase example of the specific look; Weex, at present just rough time the following document, three-terminal common code, indeed some brain hole, its internal implementation should have a considerable degree of learning value, but its idea, 3-terminal common code, means to take three end of the respective platform advantages of the intersection, may also mean to sacrifice 3 platforms of their respective uniqueness and advantages-- If this is really the case, that reactnative, but also can call themselves "one place to write, run everywhere"; Apicloud, Commercial Drive, from the product point of view, more perfect, mixed development is only part of the service, according to the current development route, if the future of HTML development a little more quickly, perhaps there will be a great possibility.
Reference Resources
    • This section is complete to execute Xcode engineering code, less than 0.5M
    • Series of articles dedicated to GitHub project
    • Cfbundledisplayname returns ' null '

Implementing hot updates for resource files such as iOS pictures (v): A simple and complete resource Hot Update page

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.