美文网首页
动态库加载过程

动态库加载过程

作者: 碧玉小瑕 | 来源:发表于2017-07-14 11:24 被阅读52次

    1,将framework引入工程中比如Dylib.framework

    2,设置target--->Build Phases--->Link Binary with Libraries,添加framework

    3,设置target--->Build Phases---->Copy Bindle Resource,

    4,添加Copy Files,

    如图:

    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];

    }

    }

    三个函数可看到效果。

    相关文章

      网友评论

          本文标题:动态库加载过程

          本文链接:https://www.haomeiwen.com/subject/ppynhxtx.html