熱更新--動態載入framework

有稜角的圓發表於2016-08-17

1.準備工作:先自己封裝一個framework:http://www.cnblogs.com/sunjianfei/p/5781863.html

2.把封裝好的framework壓縮成zip,放到本地伺服器端

3.下載壓縮包,並且解壓,參照:http://www.cnblogs.com/sunjianfei/p/5781799.html

4.新增並設定Application requires iPhone env。。。。。為yes

5.動態載入下載下來的framework庫檔案:

  NSString *documentDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
        NSString *bundlePath = [NSString stringWithFormat:@"%@/%@",documentDirectory,@"JFTestFramework.framework"];
        NSLog(@"2-------%@",bundlePath);
        if (![[NSFileManager defaultManager] fileExistsAtPath:bundlePath]) {
            NSLog(@"file not exist");
            return;
        }
        NSBundle *bundle = [NSBundle bundleWithPath:bundlePath];
        
        if (!bundle || ![bundle load]) {
            NSLog(@"bundle load error");
        }
        Class loadClass= [bundle classNamed:@"JFDylib"];
        
        if (!loadClass) {
            NSLog(@"get bundle class fail");
            return;
        }
        
        NSObject *bundleObj = [loadClass new];
        
        [bundleObj performSelector:@selector(showViewAfterVC: inBundle:) withObject:self withObject:bundle];

 

相關文章