1,将framework引入工程中比如Dylib.framework
2,设置target--->Build Phases--->Link Binary with Libraries,添加framework
3,设置target--->Build Phases---->Copy Bindle Resource,
4,添加Copy Files,
如图:
![](https://img.haomeiwen.com/i1286371/6c61c476deaf0b20.png)
![](https://img.haomeiwen.com/i1286371/e4cd484dc15f7346.png)
5,设置Build Settings---->Linking----->Runpath Search Paths---->@executable_path
6,代码部分:
在使用的地方引入#import <Dylib/Dylib.h>
- (IBAction)bundleLoadAction:(id)sender {
NSLog(@"bundleLoadAction");
//NSString *documentsPath = [NSString stringWithFormat:@"%@/Documents/Dylib.framework",NSHomeDirectory()];
NSString*documentsPath = [NSStringstringWithFormat:@"%@/Dylib.framework",[[NSBundlemainBundle]bundlePath]];
[selfbundleLoadDylibWithPath:documentsPath];
}
- (void)bundleLoadDylibWithPath:(NSString*)path
{
_libPath= path;
NSError*err =nil;
NSBundle*bundle = [NSBundlebundleWithPath:path];
if([bundleloadAndReturnError:&err]) {
NSLog(@"bundle load framework success.");
}else{
NSLog(@"bundle load framework err:%@",err);
}
}
- (IBAction)trigerAction:(id)sender {
NSLog(@"trigerAction");
ClassrootClass =NSClassFromString(@"Person");
if(rootClass) {
idobject = [[rootClassalloc]init];
[(Person*)objectrun];
}
}
三个函数可看到效果。
网友评论