Dynamic Library Kit
CTDynamicLibKit is a dynamic library, which can load your customized dynamic library that delivered with your app or even fetched by network.
CTDynamicLibKit provided some methods to load and maintain your dynamic libraries and to call methods(in CTDynamicLibKit, I prefer to call it handler.) from your customized dynamic library.
cd ./Demo/DynamicDemo
andpod update
, so that you can useNVHTarGzip
to extract the framework you will download by network.cd ./Demo/DynamicLibDemo
andopen DynamicLibDemo.xcodeproj
, pressCommand+b
to build it- go to
Derived Data
, find the buildedDynamicLibDemo.framework
, thencd DynamicLibDemo.framework
, usetar zcvf ../a.tar.gz ./
, andcd ..
you will see thea.tar.gz
generated. - upload
a.tar.gz
to your own website so that you will have a download URL which looks likehttp://1.2.3.4/a.tar.gz
. open ./Demo/DynamicDemo.xcodeworkspace
, modifyViewController.m:47
to the correct URL you just generated.- press
Command+r
to run DynamicDemo, and wait a few seconds, your app will download and load the framework you just uploaded, and show a UIAlertView.
- create a new XCode project, and choose
Cocoa Touch Framework
.
- drag the compiled
CTDynamicLibKit
into your project, copy if needed
- go to
Build Phases
of yourTargets
, removeCTDynamicLibKit.framework
fromLink Binary With Libraries
.
- create a Class, let's say it
TestObj
, which import<CTDynamicLibKit/CTDynamicLibKit.h>
and conforms to protocolCTDynamicLibPrincipalClassProtocol
, and implement them.
/** TestObj.h **/
#import <UIKit/UIKit.h>
#import <CTDynamicLibKit/CTDynamicLibKit.h>
@interface TestObj : NSObject <CTDynamicLibPrincipalClassProtocol>
@end
/** TestObj.m **/
#import "TestObj.h"
@implementation TestObj
#pragma mark - CTDynamicLibPrincipalClassProtocol
+ (instancetype)sharedInstance
{
static TestObj *_testObj = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
_testObj = [[TestObj alloc] init];
});
return _testObj;
}
- (void)performHandler:(NSString *)handler
withParams:(NSDictionary *)params
processingCallback:(NSDictionary *(^)(NSDictionary *))processingCallback
completion:(void (^)(NSDictionary *, NSError *))completion
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"casa" message:@"casa" delegate:nil cancelButtonTitle:@"ok" otherButtonTitles:nil];
[alert show];
if (completion) {
completion(@{@"key1":@"value1"}, nil);
}
}
@end
- open
Info.plist
, add a keyRegisted Handlers
with value type ofArray
, and insert handler names as you want.
- add a key
Principal class
(just inputPrincipal
, and xcode will complete it), input the class name you just created:TestObj