• <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>

            專(zhuān)職C++

            不能停止的腳步

              C++博客 :: 首頁(yè) :: 聯(lián)系 :: 聚合  :: 管理
              163 Posts :: 7 Stories :: 135 Comments :: 0 Trackbacks

            常用鏈接

            留言簿(28)

            我參與的團(tuán)隊(duì)

            搜索

            •  

            最新評(píng)論

            閱讀排行榜

            評(píng)論排行榜

            轉(zhuǎn):http://www.cnblogs.com/zjoch/p/6018229.html

            目前能夠?qū)崿F(xiàn)熱更新的方法,總結(jié)起來(lái)有以下三種

            1. 使用FaceBook 的開(kāi)源框架 reactive native,使用js寫(xiě)原生的iOS應(yīng)用

            ios app可以在運(yùn)行時(shí)從服務(wù)器拉取最新的js文件到本地,然后執(zhí)行,因?yàn)閖s是一門(mén)動(dòng)態(tài)的

            腳本語(yǔ)言,所以可以在運(yùn)行時(shí)直接讀取js文件執(zhí)行,也因此能夠?qū)崿F(xiàn)ios的熱更新

             

            2. 使用lua 腳本。lua腳本如同js 一樣,也能在動(dòng)態(tài)時(shí)被。之前憤怒的小鳥(niǎo)使用

            lua腳本做的一個(gè)插件 wax,可以實(shí)現(xiàn)使用lua寫(xiě)ios應(yīng)用。熱更新時(shí),從服務(wù)器拉去lua腳本

            然后動(dòng)態(tài)的執(zhí)行就可以了。遺憾的是 wax目前已經(jīng)不更新了。

             

            上面是網(wǎng)上現(xiàn)在能夠搜到的熱更新方法。

            xcode 6 之后,蘋(píng)果開(kāi)放了 ios 的動(dòng)態(tài)庫(kù)編譯權(quán)限。所謂的動(dòng)態(tài)庫(kù),其實(shí)就是可以在運(yùn)行時(shí)加載。

            正好利用這一個(gè)特性,用來(lái)做ios的熱更新。

            1.

            建立一個(gè)動(dòng)態(tài)庫(kù),如圖:

            動(dòng)態(tài)庫(kù)包含需要使用的viewCOntroller,當(dāng)然可以包含任何需要使用的自定義ui和邏輯。

            動(dòng)態(tài)庫(kù)的入口是一個(gè)jkDylib的類(lèi)。它的.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  


            上述代碼意圖非常明顯,

             

            就是調(diào)用該動(dòng)態(tài)庫(kù)的時(shí)候

             

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

            在該函數(shù)中,創(chuàng)建一個(gè)viewController 然后使用mainBundler 的navigationController  push 新建的viewController,顯示動(dòng)態(tài)庫(kù)的ui界面。

             

            而動(dòng)態(tài)庫(kù)中的JKViewController 內(nèi)容則可以根據(jù)需要隨便定義。

             

            2. 完成上述動(dòng)態(tài)庫(kù)的編譯工作后,現(xiàn)在需要做的就是在主工程中,寫(xiě)一段加載該動(dòng)態(tài)庫(kù)的代碼。

            主工程目錄如下:

            在最重要的viewCotrooler里面,定義了加載動(dòng)態(tài)庫(kù)的方法:

             

            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視圖中有一個(gè)按鈕,點(diǎn)擊按鈕后,從 document目錄下面找到動(dòng)態(tài)庫(kù)(雖然此時(shí)document下并沒(méi)有動(dòng)態(tài)庫(kù)),動(dòng)態(tài)庫(kù)的名稱(chēng)約定好味

             

            JKDylib.framework

            然后使用NSBundle 加載該動(dòng)態(tài)庫(kù),具體見(jiàn)代碼。

            加載成功后,調(diào)用在動(dòng)態(tài)庫(kù)中實(shí)現(xiàn)的方法

             

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

            編譯該工程,然后運(yùn)行到手機(jī)上,然后退出該程序

             

             

            3. 打開(kāi)itunes 然后將動(dòng)態(tài)庫(kù)同步到剛才的測(cè)試工程目錄下。

             

            4.在此打開(kāi)測(cè)試工程程序,點(diǎn)擊button,則會(huì)發(fā)現(xiàn)能夠進(jìn)入在動(dòng)態(tài)庫(kù)中定義的ui界面了。

             

            上面工程的參考代碼 在 

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

             

            關(guān)于動(dòng)態(tài)更新的思考:

             

            采用動(dòng)態(tài)庫(kù)方式實(shí)現(xiàn)熱更新其實(shí)還是有一個(gè)問(wèn)題,就是如何在主工程和動(dòng)態(tài)庫(kù)之間共享組建

            比如網(wǎng)絡(luò)組件以及其他等等第三方組件。

            目前我沒(méi)發(fā)現(xiàn)好方法,只能在動(dòng)態(tài)庫(kù)和主工程之間分別添加并且編譯。

            posted on 2016-11-29 12:38 冬瓜 閱讀(683) 評(píng)論(0)  編輯 收藏 引用 所屬分類(lèi): 轉(zhuǎn)貼
            国产精品九九久久免费视频 | 国产aⅴ激情无码久久| 久久婷婷五月综合色99啪ak | 97精品国产97久久久久久免费| 国内精品久久久久久久影视麻豆 | 久久久久亚洲AV无码专区首JN| 久久精品国产亚洲AV香蕉| 91精品国产色综久久| 亚洲人成网亚洲欧洲无码久久| 精品国产一区二区三区久久| 思思久久好好热精品国产| 久久久精品免费国产四虎| 国产精品乱码久久久久久软件| 欧美日韩中文字幕久久伊人| 久久99精品久久久大学生| A级毛片无码久久精品免费| 无码人妻精品一区二区三区久久| 99久久久久| 99久久超碰中文字幕伊人| 久久久久se色偷偷亚洲精品av| 久久99精品国产麻豆蜜芽| 99久久国产热无码精品免费| 中文无码久久精品| 精品国产乱码久久久久软件| 久久AⅤ人妻少妇嫩草影院| 72种姿势欧美久久久久大黄蕉| 99精品久久精品一区二区| 久久亚洲国产精品五月天婷| 国产精品热久久毛片| 国内精品久久久久影院免费| 国内精品久久久久久99蜜桃| 久久久久久国产精品无码超碰| 国产成人久久精品一区二区三区 | 久久国产精品久久久| 中文字幕无码免费久久| 久久人人爽人人爽人人片av麻烦 | 99蜜桃臀久久久欧美精品网站 | 久久综合久久美利坚合众国| 久久亚洲精品国产精品婷婷| 伊人久久国产免费观看视频| 狠狠色婷婷久久综合频道日韩|