• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            專職C++

            不能停止的腳步

              C++博客 :: 首頁 :: 聯系 :: 聚合  :: 管理
              163 Posts :: 7 Stories :: 135 Comments :: 0 Trackbacks

            常用鏈接

            留言簿(28)

            我參與的團隊

            搜索

            •  

            最新評論

            閱讀排行榜

            評論排行榜

            轉:http://www.cnblogs.com/zjoch/p/6018229.html

            目前能夠實現熱更新的方法,總結起來有以下三種

            1. 使用FaceBook 的開源框架 reactive native,使用js寫原生的iOS應用

            ios app可以在運行時從服務器拉取最新的js文件到本地,然后執行,因為js是一門動態的

            腳本語言,所以可以在運行時直接讀取js文件執行,也因此能夠實現ios的熱更新

             

            2. 使用lua 腳本。lua腳本如同js 一樣,也能在動態時被。之前憤怒的小鳥使用

            lua腳本做的一個插件 wax,可以實現使用lua寫ios應用。熱更新時,從服務器拉去lua腳本

            然后動態的執行就可以了。遺憾的是 wax目前已經不更新了。

             

            上面是網上現在能夠搜到的熱更新方法。

            xcode 6 之后,蘋果開放了 ios 的動態庫編譯權限。所謂的動態庫,其實就是可以在運行時加載。

            正好利用這一個特性,用來做ios的熱更新。

            1.

            建立一個動態庫,如圖:

            動態庫包含需要使用的viewCOntroller,當然可以包含任何需要使用的自定義ui和邏輯。

            動態庫的入口是一個jkDylib的類。它的.h和.m文件分別如下:

             

            1. //  
            2. //  JKDylib.h  
            3. //  JKDylb  
            4. //  
            5. //  Created by wangdan on 15/7/5.  
            6. //  Copyright (c) 2015年 wangdan. All rights reserved.  
            7. //  
            8.   
            9. #import <Foundation/Foundation.h>  
            10.   
            11. @interface JKDylib : NSObject  
            12.   
            13. -(void)showViewAfterVC:(id)fromVc inBundle:(NSBundle*)bundle;  
            14.   
            15. @end  


            .m文件

             

             

            1. //  
            2. //  JKDylib.m  
            3. //  JKDylb  
            4. //  
            5. //  Created by wangdan on 15/7/5.  
            6. //  Copyright (c) 2015年 wangdan. All rights reserved.  
            7. //  
            8.   
            9. #import "JKDylib.h"  
            10. #import "JKViewController.h"  
            11.   
            12. @implementation JKDylib  
            13.   
            14. -(void)showViewAfterVC:(id)fromVc inBundle:(NSBundle*)bundle  
            15. {  
            16.     if (fromVc == nil ) {  
            17.         return;  
            18.     }  
            19.       
            20.     JKViewController *vc = [[JKViewController alloc] init];  
            21.     UIViewController *preVc = (UIViewController *)fromVc;  
            22.       
            23.     if (preVc.navigationController) {  
            24.         [preVc.navigationController pushViewController:vc animated:YES];  
            25.     }  
            26.     else {  
            27.         UINavigationController *navi = [[UINavigationController alloc] init];  
            28.         [navi pushViewController:vc animated:YES];  
            29.     }  
            30.       
            31. }  
            32. @end  


            上述代碼意圖非常明顯,

             

            就是調用該動態庫的時候

             

            1. -(void)showViewAfterVC:(id)fromVc inBundle:(NSBundle*)bundle  

            在該函數中,創建一個viewController 然后使用mainBundler 的navigationController  push 新建的viewController,顯示動態庫的ui界面。

             

            而動態庫中的JKViewController 內容則可以根據需要隨便定義。

             

            2. 完成上述動態庫的編譯工作后,現在需要做的就是在主工程中,寫一段加載該動態庫的代碼。

            主工程目錄如下:

            在最重要的viewCotrooler里面,定義了加載動態庫的方法:

             

            1. //  
            2. //  ViewController.m  
            3. //  DylibTest  
            4. //  
            5. //  Created by wangdan on 15/7/5.  
            6. //  Copyright (c) 2015年 wangdan. All rights reserved.  
            7. //  
            8.   
            9. #import "ViewController.h"  
            10. #import "AFNetWorking.h"  
            11.   
            12. @interface ViewController ()  
            13.   
            14. @end  
            15.   
            16. @implementation ViewController  
            17.   
            18. - (void)viewDidLoad {  
            19.     [super viewDidLoad];  
            20.     self.view.backgroundColor = [UIColor whiteColor];  
            21.     self.title = @"bundle test";  
            22.       
            23.     AFHTTPRequestOperationManager *manager = [[AFHTTPRequestOperationManager alloc] init];  
            24.     manager.responseSerializer = [AFJSONResponseSerializer serializer];  
            25.     NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.baidu.com"]];  
            26.     [manager HTTPRequestOperationWithRequest:request success:^(AFHTTPRequestOperation *operation, id responseObject) {  
            27.         NSLog(@"request success");  
            28.     } failure:^(AFHTTPRequestOperation *operation, NSError *error) {  
            29.         NSLog(@"request failure");  
            30.     }];  
            31.       
            32.       
            33.       
            34.     UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(0, 100, 100, 50)];  
            35.     btn.backgroundColor = [UIColor blueColor];  
            36.       
            37.     [btn addTarget:self  
            38.             action:@selector(btnHandler)  
            39.   forControlEvents:UIControlEventTouchUpInside];  
            40.       
            41.     [self.view addSubview:btn];  
            42.       
            43.     NSString *document = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];  
            44.       
            45.     BOOL writeResult =  
            46.     [@"hellow" writeToFile:[NSString stringWithFormat:@"%@/%@",document,@"hello.plist"] atomically:YES encoding:NSUTF8StringEncoding error:nil];  
            47.       
            48.     // Do any additional setup after loading the view, typically from a nib.  
            49. }  
            50.   
            51.   
            52. -(void)btnHandler  
            53. {  
            54.       
            55.     //AFHTTPRequestOperationManager *manager = [[AFHTTPRequestOperationManager alloc] init];  
            56.     //manager.responseSerializer = [AFJSONResponseSerializer serializer];  
            57.    // NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.baidu.com"]];  
            58.    // [manager HTTPRequestOperationWithRequest:request success:^(AFHTTPRequestOperation *operation, id responseObject) {  
            59.     //    NSLog(@"request success");  
            60.    // } failure:^(AFHTTPRequestOperation *operation, NSError *error) {  
            61.       // NSLog(@"request failure");  
            62.     //}];  
            63.       
            64.     NSString *documentDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];  
            65.     NSString *bundlePath = [NSString stringWithFormat:@"%@/%@",documentDirectory,@"JKDylb.framework"];  
            66.       
            67.     if (![[NSFileManager defaultManager] fileExistsAtPath:bundlePath]) {  
            68.         NSLog(@"file not exist ,now  return");  
            69.         return;  
            70.     }  
            71.     NSBundle *bundle = [NSBundle bundleWithPath:bundlePath];  
            72.       
            73.     if (!bundle || ![bundle load]) {  
            74.         NSLog(@"bundle load error");  
            75.     }  
            76.       
            77.     Class loadClass = [bundle principalClass];  
            78.     if (!loadClass) {  
            79.         NSLog(@"get bundle class fail");  
            80.         return;  
            81.     }  
            82.     NSObject *bundleObj = [loadClass new];  
            83.     [bundleObj performSelector:@selector(showViewAfterVC:inBundle:) withObject:self withObject:bundle];  
            84.       
            85.     NSString *framePath = [[NSBundle mainBundle] privateFrameworksPath];  
            86.     NSLog(@"framePath is %@",framePath);  
            87.       
            88.     NSLog(@"file attri \n %@",bundle.localizations);  
            89.       
            90. //    [bundleObj showViewAfterVC:self inBundle:bundle];  
            91. }  
            92.   
            93. - (void)didReceiveMemoryWarning {  
            94.     [super didReceiveMemoryWarning];  
            95.     // Dispose of any resources that can be recreated.  
            96. }  
            97.   
            98. @end  


            viewController視圖中有一個按鈕,點擊按鈕后,從 document目錄下面找到動態庫(雖然此時document下并沒有動態庫),動態庫的名稱約定好味

             

            JKDylib.framework

            然后使用NSBundle 加載該動態庫,具體見代碼。

            加載成功后,調用在動態庫中實現的方法

             

            1. [bundleObj performSelector:@selector(showViewAfterVC:inBundle:) withObject:self withObject:bundle];  
            2.      

            編譯該工程,然后運行到手機上,然后退出該程序

             

             

            3. 打開itunes 然后將動態庫同步到剛才的測試工程目錄下。

             

            4.在此打開測試工程程序,點擊button,則會發現能夠進入在動態庫中定義的ui界面了。

             

            上面工程的參考代碼 在 

            http://download.csdn.net/detail/j_akill/8891881

             

            關于動態更新的思考:

             

            采用動態庫方式實現熱更新其實還是有一個問題,就是如何在主工程和動態庫之間共享組建

            比如網絡組件以及其他等等第三方組件。

            目前我沒發現好方法,只能在動態庫和主工程之間分別添加并且編譯。

            posted on 2016-11-29 12:38 冬瓜 閱讀(688) 評論(0)  編輯 收藏 引用 所屬分類: 轉貼
            久久国产精品77777| 久久99精品久久只有精品| 久久婷婷国产综合精品| 久久久噜噜噜久久中文字幕色伊伊 | 99精品久久久久久久婷婷| 69久久精品无码一区二区| 国产精品久久久久无码av| 久久精品草草草| 免费精品久久天干天干| AV狠狠色丁香婷婷综合久久| 免费无码国产欧美久久18| 久久精品午夜一区二区福利| 亚洲精品国产美女久久久 | 久久免费视频6| 99久久久精品免费观看国产| 亚洲va久久久噜噜噜久久天堂| 亚洲人成网亚洲欧洲无码久久| 久久国产成人精品麻豆| 精品国产福利久久久| 久久久精品久久久久特色影视| 久久黄色视频| 亚洲中文字幕无码久久2017| 亚洲精品蜜桃久久久久久| 欧洲性大片xxxxx久久久| 国产精品99久久久精品无码 | 2021久久国自产拍精品| 久久黄视频| 国产亚洲精午夜久久久久久| 午夜视频久久久久一区| 久久久久国产精品熟女影院| 国产精品久久成人影院| 97视频久久久| 香蕉久久影院| 天堂无码久久综合东京热| 久久99精品国产99久久6男男| 国内精品久久久久影院老司| 99国产精品久久久久久久成人热| 中文字幕无码久久人妻| 久久久国产99久久国产一| 亚洲一本综合久久| 91精品国产91热久久久久福利|