How to implement iOS hot update

Source: Internet
Author: User

Recently by the Apple Audit, every commit version has to wait a week to two weeks of audit time, I can't stand this speed, so decided to study there is no other way to skip the commit version of this step, the same can fix the bug, so I found the Jspatch, Maybe a lot of people think this is a very big technology, in fact, we just need to introduce a very small engine file in the project, you can use JavaScript to call any objective-c native interface, replace any objective-c native method. Of course, is mainly used to release JS script to replace the native OBJECTIVE-C code, real-time repair online bug.

Jspatch code Everyone can go to github download

First of all, jspatch implementation of the internal principle: Jspatch can do through JS call and rewrite OC method The most fundamental reason is that objective-c is a dynamic language, OC on all methods of the call/class generation through the Objective-c runtime at runtime, We can use the class name and method name to reflect the corresponding class and method, or replace the method of a class with a new implementation, or you can register a new class to add a method to the class. Here is not the details of the runtime, the relevant information I will be in the follow-up blog to introduce, we can wait. So the Jspatch principle is: JS pass string to Oc,oc through the Runtime interface call and replace OC method. This is easy to understand, the role of JS is just a messenger role, the specific implementation or rely on our OC, so that OC or the world's most beautiful language, haha.

At the same time here to give everyone a better site point here. This is a OC to JS a tool site.

Here is a demonstration of the specific steps to implement

- (void) viewdidload{uitableview* TV = [[UITableView Alloc]initwithframe:Self. View. Bounds Style:Uitableviewstyleplain];Self. Mqtableview = TV;Self. Mqtableview. Delegate =SelfSelf. Mqtableview. DataSource =Self [Self. View Addsubview:Self. Mqtableview];}#pragma mark--uitableviewdatasource-(Nsinteger) TableView: (UITableView *) TableView numberofrowsinsection: (Nsinteger) section{Return3;} - (UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) indexpath{Staticnsstring* i=@ "Cell";uitableviewcell* cell = [TableView dequeuereusablecellwithidentifier:i];if (cell = =Nil) {cell =[[UITableViewCell Alloc]initwithstyle:uitableviewcellstyledefault reuseidentifier:i]; } cell.textlabel.text = @ " Meiqing "; Cell.backgroundcolor = [uicolor WhiteColor]; return Cell;} -(void) TableView: (uitableview *) TableView Didselectrowatindexpath: (nsindexpath *) indexpath{self< Span class= "hljs-variable" >.datasource = @[@ "1", @ "2"]; //will definitely go beyond the array range resulting crash nsstring *content = self.datasource[indexpath                

The result of the display is this


Screen shot 2015-12-10 a.m. 12.09.15.png

The above picture is not modified when the display, when I click on the third line will definitely flash back, how to fix it? This time will not be issued version, the server can send us a JS file, the contents of the file is like this


Screen shot 2015-12-10 a.m. 12.44.14.png

At the same time, we call this JS in the appdelegate can be, as follows:


Screen shot 2015-12-10 a.m. 12.45.25.png

Run again and there will be no flash back.
The whole process is actually quite simple, I hope you can accept, if you like my article, you can follow my subsequent articles.

GitHub demo included

Weibo account: Meichaqing (click to follow)



Wen/Meiqing (Jane book author)
Original link: http://www.jianshu.com/p/8cec322531ae
Copyright belongs to the author, please contact the author to obtain authorization, and Mark "book author".

How to implement iOS hot update

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.