Achieve hot update of iOS images and other resource files (5): A simple and complete resource hot Update page, ios resource file

Source: Internet
Author: User
Tags file url

Achieve hot update of iOS images and other resource files (5): A simple and complete resource hot Update page, ios resource file
Introduction

A simple page contains an image, version number, App name, and so on, which highlights the complete integration examples of articles in each series.

Motivation and Significance

This is the last article in the series. I took the time to write it down today and accept it. On the basis of the fourth article, the article will simply expand the code to implement online download and reset the change function.

If you can carefully read the first four articles, the example given in the fifth article can be understood as insignificant. however, most of the time, we may only need a simple solution, that is, something we can use, we need to first see a brief example to see the effect and then solve the problem of whether to continue reading. in this way, for a long time later, people who are directed to this series of articles by links of search engines or other articles for various reasons may want to see a brief example to decide the series of articles, at their time, is it still meaningful.

So far, my position on the blog record itself is still a tool for auxiliary thinking. when you see this article, you may already be using Xcode9 Xcode10, and the code examples may not be able to run, however, I believe that the reference links presented in each article and some of the ideas that have been exposed may still inspire you.

Ideas and core code:

I need to first expand the method for updating resources so that the updated results can be returned after the update is complete, so that I can perform further operations, such as re-displaying an image:

+ (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: %@", urlStr, 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 custom online update 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. Considering the future scalability and current needs, it supports the block outgoing operation result:

+ (void )yf_reset:(void (^)(BOOL success, NSError * error))completionHandler{    if ( ! completionHandler) {        completionHandler = ^(BOOL success, NSError * error){            // nothing to do...        };    }    [[NSUserDefaults standardUserDefaults] setObject:nil forKey: [self yf_sourcePatchKey]];    completionHandler(YES, nil);}

 

It is easy to use. After resetting, update the film:

- (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);        }    }];}

 

Summary of articles

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

Some data
  • Open-source China has recommended two blogs: Four published series of articles, two of which have received full-site recommendations from the OSC.
  • I recommend two articles on the homepage of the simplified book for an award: The technical attributes of the simplified book may not be very strong. However, when searching for technical materials recently, many links are directed to the simplified book, in addition, most of the information is very timely and fresh, and the reason is unknown, so recently I also began to update articles in the short book. As for receiving the reward, there is actually only 2 yuan of hot money, however, it is obvious that this shoes were directed to my article when searching for a piece of information, and from the perspective of his comments, it did help to some extent-I think, this is what makes bloggers happy to be visible to those who need it!
  • Weibo-related blog posts are forwarded by three major vpcs: to some extent, I think this is an acknowledgment. however, I don't actually play with Weibo. Weibo's information is too easy to be drowned. However, if I only consider the attributes of dissemination, Weibo's diffusion effect is actually excellent.
  • After segmentfault added the article to the headlines, he was liked twice by segmentfault's CEO Gao Yang Sunny and forwarded it once on Weibo. I was flattered, but later I thought people would just want to push out the new "toutiao.com" feature.
  • The csdn homepage is recommended once: the original version of the notification is, "Your Implementation of iOS images and other resource files is hot-updated (4): a minimal patch update logic is recommended to the homepage! "This is really memorable! At the beginning, I published an article. If there is an external link, CSDN must be reviewed before it can be publicly seen!
Tips
  • Job first, blog sharing Second: I don't expect to earn a draft fee from my blog in the future, which means that all work affairs must always be handled first. therefore, the blog update time cannot be fixed. in addition, I don't want blog sharing to be a burden. If I really don't feel down or have other things in my life, I will leave it there and write it later.
  • Do not be bound by previous themes. Write the series that you really need or are interested in: in terms of time, it is indeed one month later than expected; however, the actual effect is much better than the previous Spark series. however, when I decided on the content of this series, I was also very entangled in whether to continue Spark big data or share my thoughts on in-depth research, resource Package optimization problems that have been unable to find time. in the end, I chose the latter because there are not many Spark scenarios in my work.
  • Recording ideas and reference resources may be more important than the solution itself: More, reading other people's blog experience; less likely to encounter completely consistent problems, and in many cases, I found the answer from the reference of relevant bloggers for more details on similar questions. In addition, various references may also give people a very high feeling.
  • The time you need is longer than you expected: The article that you think can be done in half an hour may take two hours to finish. A technical point that you think is a simple answer, after deduction of a specific detail, it may be more experienced than you think. when you realize that what you are doing will be publicly read and appreciated, you may want to do more, check more, and optimize more, do not want to appear too low.
Small plan
  • Theme, stick to a series of articles: I found that series of articles are really helpful for me to carry out and insist on in-depth and orderly thinking.
  • Theme, determined to be mobile hybrid development: I have been using ReactNative for App development in the past year, but simply using it cannot satisfy me. I want to study some internal implementation mechanisms in depth. in comparison, we will look at the barely community-driven Weex, and pay attention to the commercial-driven APICloud platform in China.
  • The content will involve iOS, Android, HTML5, and automated scripts: iOS is your job, and Android and HTML are your urgent skills, the ability to write automated scripts determines, to a large extent, the ability to automatically process complex information and the future development. Lisp is the first language in the universe, however, currently, basic shell scripts are mostly used.
  • The article and comments should only talk about technology: the direction of Mixed development represented by ReactNative has been recognized by the first-line technical companies represented by BAT in China to a certain extent, you can go to the showcase example to take a look; Weex, at present, only a rough reading of the document, three-end public code, indeed some brain holes, its internal implementation should have a considerable degree of learning value, however, the concept is not the same. Three-end code sharing means that the intersection of the advantages of the Three-end platform is required, it may also mean that the uniqueness and advantages of the three platforms should be sacrificed-if this is the case, ReactNative can also claim to be "one write, run everywhere"; APICloud, commercial drivers: from a product perspective, hybrid development is only a part of the service. According to the current development path, if HTML develops more rapidly in the future, it may lead to a great deal of opportunities.
Reference resources
  • This section contains the complete Xcode project code, less than 0.5 Mb
  • Exclusive github project for series of articles
  • CFBundleDisplayName returns 'null'

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.