目前能够实现热更新的方法,总结起来有以下三种

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. #import <Foundation/Foundation.h>
  9. @interface JKDylib : NSObject
  10. -(void)showViewAfterVC:(id)fromVc inBundle:(NSBundle*)bundle;
  11. @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. #import "JKDylib.h"
  9. #import "JKViewController.h"
  10. @implementation JKDylib
  11. -(void)showViewAfterVC:(id)fromVc inBundle:(NSBundle*)bundle
  12. {
  13. if (fromVc == nil ) {
  14. return;
  15. }
  16. JKViewController *vc = [[JKViewController alloc] init];
  17. UIViewController *preVc = (UIViewController *)fromVc;
  18. if (preVc.navigationController) {
  19. [preVc.navigationController pushViewController:vc animated:YES];
  20. }
  21. else {
  22. UINavigationController *navi = [[UINavigationController alloc] init];
  23. [navi pushViewController:vc animated:YES];
  24. }
  25. }
  26. @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. #import "ViewController.h"
  9. #import "AFNetWorking.h"
  10. @interface ViewController ()
  11. @end
  12. @implementation ViewController
  13. - (void)viewDidLoad {
  14. [super viewDidLoad];
  15. self.view.backgroundColor = [UIColor whiteColor];
  16. self.title = @"bundle test";
  17. AFHTTPRequestOperationManager *manager = [[AFHTTPRequestOperationManager alloc] init];
  18. manager.responseSerializer = [AFJSONResponseSerializer serializer];
  19. NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.baidu.com"]];
  20. [manager HTTPRequestOperationWithRequest:request success:^(AFHTTPRequestOperation *operation, id responseObject) {
  21. NSLog(@"request success");
  22. } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
  23. NSLog(@"request failure");
  24. }];
  25. UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(0, 100, 100, 50)];
  26. btn.backgroundColor = [UIColor blueColor];
  27. [btn addTarget:self
  28. action:@selector(btnHandler)
  29. forControlEvents:UIControlEventTouchUpInside];
  30. [self.view addSubview:btn];
  31. NSString *document = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
  32. BOOL writeResult =
  33. [@"hellow" writeToFile:[NSString stringWithFormat:@"%@/%@",document,@"hello.plist"] atomically:YES encoding:NSUTF8StringEncoding error:nil];
  34. // Do any additional setup after loading the view, typically from a nib.
  35. }
  36. -(void)btnHandler
  37. {
  38. //AFHTTPRequestOperationManager *manager = [[AFHTTPRequestOperationManager alloc] init];
  39. //manager.responseSerializer = [AFJSONResponseSerializer serializer];
  40. // NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.baidu.com"]];
  41. // [manager HTTPRequestOperationWithRequest:request success:^(AFHTTPRequestOperation *operation, id responseObject) {
  42. //    NSLog(@"request success");
  43. // } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
  44. // NSLog(@"request failure");
  45. //}];
  46. NSString *documentDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
  47. NSString *bundlePath = [NSString stringWithFormat:@"%@/%@",documentDirectory,@"JKDylb.framework"];
  48. if (![[NSFileManager defaultManager] fileExistsAtPath:bundlePath]) {
  49. NSLog(@"file not exist ,now  return");
  50. return;
  51. }
  52. NSBundle *bundle = [NSBundle bundleWithPath:bundlePath];
  53. if (!bundle || ![bundle load]) {
  54. NSLog(@"bundle load error");
  55. }
  56. Class loadClass = [bundle principalClass];
  57. if (!loadClass) {
  58. NSLog(@"get bundle class fail");
  59. return;
  60. }
  61. NSObject *bundleObj = [loadClass new];
  62. [bundleObj performSelector:@selector(showViewAfterVC:inBundle:) withObject:self withObject:bundle];
  63. NSString *framePath = [[NSBundle mainBundle] privateFrameworksPath];
  64. NSLog(@"framePath is %@",framePath);
  65. NSLog(@"file attri \n %@",bundle.localizations);
  66. //    [bundleObj showViewAfterVC:self inBundle:bundle];
  67. }
  68. - (void)didReceiveMemoryWarning {
  69. [super didReceiveMemoryWarning];
  70. // Dispose of any resources that can be recreated.
  71. }
  72. @end

viewController视图中有一个按钮,点击按钮后,从 document目录下面找到动态库(虽然此时document下并没有动态库),动态库的名称约定好味

JKDylib.framework

然后使用NSBundle 加载该动态库,具体见代码。

加载成功后,调用在动态库中实现的方法

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

编译该工程,然后运行到手机上,然后退出该程序

3. 打开itunes 然后将动态库同步到刚才的测试工程目录下。

4.在此打开测试工程程序,点击button,则会发现能够进入在动态库中定义的ui界面了。

上面工程的参考代码 在

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

关于动态更新的思考:

采用动态库方式实现热更新其实还是有一个问题,就是如何在主工程和动态库之间共享组建

比如网络组件以及其他等等第三方组件。

目前我没发现好方法,只能在动态库和主工程之间分别添加并且编译。

ios app 实现热更新(无需发新版本实现app添加新功能)的更多相关文章

  1. H5 App实现热更新,不需要重新安装app

    直接上代码吧,你竟然搜到了我的文章就应该知道了,为什么要热更新 //app热更新下载 //假定字符串的每节数都在5位以下 function toNum(a) { //也可以这样写 var c=a.sp ...

  2. ios app 实现热更新(无需发新版本号实现app加入新功能)

    眼下可以实现热更新的方法,总结起来有下面三种 1. 使用FaceBook 的开源框架 reactive native,使用js写原生的ios应用 ios app能够在执行时从server拉取最新的js ...

  3. Egret打包App Android热更新(4.1.0)

    官网教程:http://developer.egret.com/cn/github/egret-docs/Native/native/hotUpdate/index.html 详细可看官网教程,我这里 ...

  4. React Native热更新(iOS)-Pushy

    React Native的出现,使的开发iOS代码出现了更便捷的方式.由于RN是使用脚本语言编写的,实现了"解释执行"的方式,而这种执行方式的修改只需替换脚步即可,不需要重新发布程 ...

  5. React Native之code-push的热更新(ios android)

    React Native之code-push的热更新(ios android) React Native支持大家用React Native技术开发APP,并打包生成一个APP.在动态更新方面React ...

  6. [Android教程] Cordova开发App入门(二)使用热更新插件

    前言 不知各位遇没遇到过,刚刚发布的应用,突然发现了一个隐藏极深的“碧油鸡(BUG)”,肿么办!肿么办!肿么办!如果被老板发现,一定会让程序员哥哥去“吃鸡”.但是想要修复这个“碧油鸡”,就必须要重新打 ...

  7. 热更新,App双开,App隐藏,App试用 -- Replugin的实际应用(原创)

    热更新,App双开,App隐藏,App试用 -- Replugin的实际应用(原创) RePlugin是Qihoo 360公司的开源框架,原本目的是用于热更新.但是,这个框架提供的功能远远超出了热更新 ...

  8. ReactNative 告别CodePush,自建热更新版本升级环境

    微软的CodePush热更新非常难用大家都知道,速度跟被墙了没什么区别. 另外一方面,我们不希望把代码放到别人的服务器.自己写接口更新总归感觉安全一点. so,就来自己搞个React-Native A ...

  9. golang 热更新技巧 负载均衡才是正道啊

    golang plugin热更新尝试 - 呵大官人的鱼塘 - 开源中国 https://my.oschina.net/scgywx/blog/1796358 golang plugin热更新尝试 发布 ...

随机推荐

  1. coreseek实战(一):windows下coreseek的安装与测试

    coreseek实战(一):windows下coreseek的安装与测试 网上关于 coreseek 在 windows 下安装与使用的教程有很多,官方也有详细的教程,这里我也只是按着官方提供的教程详 ...

  2. Xshell连接虚拟机

    一般连接虚拟机失败 原因1:ip地址错误 当输入 ifconfig 只有lo没有eth0,或者有eth0,但eth0中确没有inet addr这一行 输入命令:dhclient eth0 就可以了

  3. 短信转发Q群

    ※◆☆★☆◆※欢迎使用!!!如有问题或新功能需求请联系作者QQ:82850696*4*您使用的测试版已到期,如需继续使用,请联系作者 QQ : 82850696*0*2015-1-7 23:59:59 ...

  4. 委托 在其他类中修改form中的控件属性

    通常情况下,我们需要在其他业务类中将提示信息时时显示到主界面上,可以通过以下方式 Form1.cs using System; ; i < ; i++) {                 cb ...

  5. 斯坦福第五课:Octave 教程(Octave Tutorial)

    5.1  基本操作 5.2  移动数据 5.3  计算数据 5.4  绘图数据 5.5  控制语句:for,while,if 语句 5.6  矢量化 5.7  工作和提交的编程练习 5.1 基本操作

  6. 不用开发者账号打ipa包

    编译一下 , if -> Build Success  -> Show in Finder之后,将文件夹里的app直接拖入到iTunes里, 接着再iTunes里选中app -> S ...

  7. Mat 转 IplImage

    Mat 转 IplImage 分类: OpenCV2013-06-02 17:00 1487人阅读 评论(0) 收藏 举报 Mat 转 IplImage Mat image1; IplImage *i ...

  8. 响应式Web设计(Responsive Web design)的理念

    页面的设计与开发应当根据用户行为以及设备环境(系统平台.屏幕尺寸.屏幕定向等)进行相应的响应和调整.具体的实践方式由多方面组成,包括弹性网格和布局.图片.CSS media query的使用等.无论用 ...

  9. 六款值得推荐的android(安卓)开源框架简介

    1.volley 项目地址 https://github.com/smanikandan14/Volley-demo (1)  JSON,图像等的异步下载: (2)  网络请求的排序(scheduli ...

  10. JS判断手机访问跳转到手机站

    这里提供了六种让手机端访问网站跳转到手机端的方法: 第一种: <script> if(navigator.platform.indexOf('Win32')!=-1){ //pc //wi ...