At present, the method of heat update can be realized, and the following three kinds are summed up
1. Use Facebook's open source framework reactive native, use JS to write native iOS apps
The iOS app can pull the latest JS files from the server to local and execute them at runtime, because JS is a dynamic
scripting language, so you can read the JS file directly at run time, and thus be able to implement hot updates for iOS
2. Use the Lua script. Lua scripts, like JS, can also be animated. Before Angry Birds to use
The Lua script does a plugin wax that can be implemented using LUA to write iOS apps. When hot update, pull the Lua script from the server
Then the dynamic execution is done. Unfortunately, wax is not updated at this time.
Above is a hot Update method that can now be found on the Internet.
After Xcode 6, Apple opened the dynamic Library compilation permissions for iOS. The so-called dynamic library, in fact, can be loaded at run time.
Just take advantage of this feature to do hot updates for iOS.
1.
Create a dynamic library,
The dynamic library contains the Viewcontroller you need to use, and of course it can contain any custom UI and logic that you need to use.
The entry of a dynamic library is a Jkdylib class. Its. h and. m files are as follows:
jkdylib.h// jkdylb//// Created by Wangdan on 15/7/5.// Copyright (c) 2015 Wangdan. All rights reserved.//#import <Foundation/Foundation.h> @interface jkdylib:nsobject-(void) SHOWVIEWAFTERVC: (ID ) Fromvc Inbundle: (nsbundle*) bundle; @end
. m file
jkdylib.m// jkdylb//// Created by Wangdan on 15/7/5.// Copyright (c) 2015 Wangdan. All rights reserved.//#import "JKDylib.h" #import "JKViewController.h" @implementation jkdylib-(void) SHOWVIEWAFTERVC :(ID) Fromvc inbundle: (nsbundle*) bundle{ if (Fromvc = nil) { return; } Jkviewcontroller *VC = [[Jkviewcontroller alloc] init]; Uiviewcontroller *PREVC = (Uiviewcontroller *) Fromvc; if (prevc.navigationcontroller) { [Prevc.navigationcontroller pushviewcontroller:vc animated:yes]; } else { Uinavigationcontroller *navi = [[Uinavigationcontroller alloc] init]; [Navi Pushviewcontroller:vc Animated:yes]; } @end
The above code intent is very obvious,
is when you call the dynamic library.
-(void) SHOWVIEWAFTERVC: (ID) FROMVC inbundle: (nsbundle*) bundle
In this function, create a viewcontroller and then use the Mainbundler navigationcontroller push new Viewcontroller to display the UI interface of the dynamic library.
The Jkviewcontroller content in the dynamic library can be defined casually as needed.
2. After compiling the above dynamic library, all that is needed now is to write the code that loads the dynamic library in the main project.
The main project directory is as follows:
In the most important viewcotrooler, the method for loading the dynamic library is defined:
viewcontroller.m//dylibtest////Created by Wangdan on 15/7/5.//Copyright (c) 2015 Wangdan. All rights reserved.//#import "ViewController.h" #import "AFNetWorking.h" @interface Viewcontroller () @ End@implementation viewcontroller-(void) viewdidload {[Super viewdidload]; Self.view.backgroundColor = [Uicolor Whitecolor]; Self.title = @ "bundle Test"; Afhttprequestoperationmanager *manager = [[Afhttprequestoperationmanager alloc] init]; Manager.responseserializer = [Afjsonresponseserializer serializer]; Nsurlrequest *request = [nsurlrequest requestwithurl:[nsurl urlwithstring:@ "http://www.baidu.com"]]; [Manager httprequestoperationwithrequest:request success:^ (afhttprequestoperation *operation, id responseObject) {NSLog (@ "request Success"); } failure:^ (Afhttprequestoperation *operation, Nserror *error) {NSLog (@ "request Failure"); }]; UIButton *btn = [[UIButton alloc] initwithframe:cgrectmake (0, 100, 100, 50)]; Btn.baCkgroundcolor = [Uicolor Bluecolor]; [Btn addtarget:self Action: @selector (Btnhandler) forcontrolevents:uicontroleventtouchupinside]; [Self.view ADDSUBVIEW:BTN]; NSString *document = [Nssearchpathfordirectoriesindomains (nsdocumentdirectory, Nsuserdomainmask, YES) lastObject]; BOOL Writeresult = [@ "Hellow" writetofile:[nsstring stringwithformat:@ "%@/%@", document,@ "Hello.plist"] atomically: YES encoding:nsutf8stringencoding Error:nil]; Do any additional setup after loading the view, typically from a nib.} -(void) btnhandler{//afhttprequestoperationmanager *manager = [[Afhttprequestoperationmanager alloc] init]; Manager.responseserializer = [Afjsonresponseserializer serializer]; Nsurlrequest *request = [nsurlrequest requestwithurl:[nsurl urlwithstring:@ "http://www.baidu.com"]]; [Manager httprequestoperationwithrequest:request success:^ (afhttprequestoperation *operation, id responseObject) { NSLog (@ "Request SuCcess "); } failure:^ (Afhttprequestoperation *operation, Nserror *error) {//NSLog (@ "request Failure"); //}]; NSString *documentdirectory = [Nssearchpathfordirectoriesindomains (nsdocumentdirectory, NSUserDomainMask, YES) Lastobject]; NSString *bundlepath = [NSString stringwithformat:@ "%@/%@", documentdirectory,@ "jkdylb.framework"]; if (![ [Nsfilemanager Defaultmanager] Fileexistsatpath:bundlepath]) {NSLog (@ "File not exist, now return"); Return } nsbundle *bundle = [NSBundle Bundlewithpath:bundlepath]; if (!bundle | |![ Bundle Load]) {NSLog (@ "Bundle load Error"); } Class loadclass = [bundle Principalclass]; if (!loadclass) {NSLog (@ "Get bundle class fail"); Return } nsobject *bundleobj = [LoadClass new]; [Bundleobj performselector: @selector (showviewaftervc:inbundle:) withobject:self Withobject:bundle]; NSString *framepath = [[NSBundle mainbundle] privateframeworkspath]; NSLog (@ "Framepath is%@", Framepath); NSLog (@ "file Attri \%@", bundle.localizations); [Bundleobj showviewaftervc:self inbundle:bundle];} -(void) didreceivememorywarning {[Super didreceivememorywarning]; Dispose of any resources the can be recreated.} @end
Viewcontroller View has a button, click on the button, from the document directory to find the dynamic library (although there is no dynamic library under document), the name of the dynamic library contract good taste
Jkdylib.framework
Then use NSBundle to load the dynamic library, see Code.
When the load succeeds, the method that is implemented in the dynamic library is called
[Bundleobj performselector: @selector (showviewaftervc:inbundle:) withobject:self Withobject:bundle];
Compile the project, then run it to the phone, and then quit the program
3. Open itunes and sync the dynamic library to the test project catalog you just tested.
4. Open the test engineering program here, click on the button, you will find the ability to enter the dynamic library defined in the UI interface.
The reference code for the above project
http://download.csdn.net/detail/j_akill/8891881
Thinking about dynamic updates:
Using dynamic Library to implement thermal update there is still a problem, that is, how to share the build between the main project and the dynamic library
such as network components and other third-party components, etc.
I have not found a good method at the moment, can only be added and compiled separately between the dynamic library and the main project.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
iOS app for hot updates (no need to send new version to implement app add new feature)