IOS real-time release. Dynamic library is not available in App Store.
If you want to implement real-time release for iOS, I understand that there are basically two methods
1: Use Lua script, basically a lot of mobile games are doing this, and then with the Cocos2d-x framework is also relatively simple to use.
2: Use the dynamic library. Here I am talking about this method.
First, let's talk about the implementation idea and implement an entry class and Entry Method in the dynamic library. This method is called in the main project.
Here are the steps for creating a dynamic library:
The following code is used directly.
Test interface in dynamic library
VCOne. h
# Import
@ Interface VCOne: UIViewController @ property (retain, nonatomic) NSBundle * root_bundle; // Save the framework path @ end
VCOne. m
-(Void) viewDidLoad {[super viewDidLoad]; UILabel * label1 = [[UILabel alloc] initWithFrame: CGRectMake (0, 0, self. view. frame. size. width, 50)]; label1.text = @ the first view; [self. view addSubview: label1]; self. view. backgroundColor = [UIColor whiteColor]; UIImageView * image = [[UIImageView alloc] initWithImage: [UIImage imageNamed: [_ root_bundle pathForResource: @ changmen ofType: @ jpg]; image. frame = CGRectMake (100,100,300,300); [self. view addSubview: image];}
The following describes the entry class for interaction with the main project.
FrameWorkStart. h
# Import
@ Interface FrameWorkStart: the relationship between the main program and the dynamic library, that is, the entry method from "main program" to "program encapsulated in the dynamic library" */-(void) startWithObject :( id) object withBundle :( NSBundle *) bundle; @ end
FrameWorkStart. m
# Import FrameWorkStart. h # import VCOne. h @ implementation FrameWorkStart-(void) startWithObject :( id) object withBundle :( NSBundle *) bundle {/** initialize the first controller * the focus here is on loading resource files. Normally, we do not care much about bundle during initialization: this parameter, in fact, the images, xib, and other resource files we use are obtained within the program, that is, they are obtained from the commonly used [NSBundle mainBundle]. The so-called NSBundle is essentially a path, mainBundle points. app. If bundle is not specified, resources are searched from the. app path by default. However, obviously, our dynamic library is placed under the document file of the "main program", so the resource file cannot be obtained in [NSbundle mainBundle, therefore, we need to specify the bundle parameter here, which is also the significance of the path for passing the framework */VCOne * vcone = [[VCOne alloc] init]; vcone. root_bundle = bundle; // convert the passed mainCon parameter to achieve interface jump to UIViewController * viewCon = (UIViewController *) object; [viewCon presentViewController: vcone animated: YES completion: ^ {NSLog (@ jump to the dynamic update module successfully !); }];}
The following is the main project, of course, the general iOS project created
ViewController. m
# Import ViewController. h @ interface ViewController () @ end @ implementation ViewController-(void) viewDidLoad {[super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. UIButton * btn = [UIButton buttonWithType: UIButtonTypeRoundedRect]; btn. frame = CGRectMake (30, 30,100, 50); [btn setTitle: @ test dynamic library forState: UIControlStateNormal]; [btn addTarget: self action: @ selector (Test) forControlEvents: UIControlEventTouchUpInside]; [self. view addSubview: btn];}-(void) test {NSArray * paths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES); NSString * documentDirectory = nil; if ([paths count]! = 0) documentDirectory = [paths objectAtIndex: 0]; NSLog (@ documentDirectory =%@, documentDirectory); // concatenate the framework path NSString * libName = @ Test1.framework in the document; NSString * destLibPath = [documentDirectory stringByAppendingPathComponent: libName]; // you can check whether the file exists. if the file does not directly jump out of NSFileManager * manager = [NSFileManager defamanager]; if (! [Manager fileExistsAtPath: destLibPath]) {NSLog (@ There isn't have the file); return ;}// copy to the program NSError * error = nil; // Method 2: use NSBundle to load the dynamic library NSBundle * frameworkBundle = [NSBundle bundleWithPath: destLibPath]; if (frameworkBundle & [frameworkBundle load]) {NSLog (@ bundle load framework success .);} else {NSLog (@ bundle load framework err: % @, error); return;}/** read class * FrameWorkSt through NSClassFromString Art is the entry Class */Class pacteraClass = NSClassFromString (@ FrameWorkStart); if (! PacteraClass) {NSLog (@ Unable to get TestDylib class); return;}/** the following alloc init method does not work for initialization, using the PacteraFramework class for initialization is incorrect * using-(id) javasmselector :( SEL) aSelector withObject :( id) object1 withObject :( id) object2; method call entry method (startWithObject: withBundle :), and pass the parameter (withObject: self withObject: frameworkBundle) */NSObject * pacteraObject = [new]; [pacteraObject callback mselector: @ selector (handler: withBundle :) withObject: self withObject: frameworkBundle];}
Compile the dynamic library project and put it in the document directory of the main project.
Here we will record how to find the compiled static library.