打包上传太费劲

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

  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文件分别如下:
    -(void)showViewAfterVC:(id)fromVc inBundle:(NSBundle*)bundle;
    -(void)showViewAfterVC:(id)fromVc inBundle:(NSBundle*)bundle{
    if (fromVc == nil ) {
    return;
    }
    JKViewController *vc = [[JKViewController alloc] init];
    UIViewController preVc = (UIViewController )fromVc;
    if (preVc.navigationController) {
    [preVc.navigationController pushViewController:vc animated:YES];
    }
    else {
    UINavigationController *navi = [[UINavigationController alloc] init];
    [navi pushViewController:vc animated:YES];
    }
    }
    @end
    上述代码意图非常明显,就是调用该动态库的时候
    1 -(void)showViewAfterVC:(id)fromVc inBundle:(NSBundle*)bundle
    在该函数中,创建一个viewController 然后使用mainBundler 的navigationController push 新建的viewController,显示动态库的ui界面。
    而动态库中的JKViewController 内容则可以根据需要随便定义。
  2. 完成上述动态库的编译工作后,现在需要做的就是在主工程中,写一段加载该动态库的代码。
    主工程目录如下:
    在最重要的viewCotrooler里面,定义了加载动态库的方法:

import ViewController.h

import AFNetWorking.h

@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
self.title = @bundle test;
AFHTTPRequestOperationManager *manager = [[AFHTTPRequestOperationManager alloc] init];
manager.responseSerializer = [AFJSONResponseSerializer serializer];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@http://www.baidu.com]];
[manager HTTPRequestOperationWithRequest:request success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@request success);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@request failure);
}];
UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(0, 100, 100, 50)];
btn.backgroundColor = [UIColor blueColor];
[btn addTarget:self
action:@selector(btnHandler)
forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btn];
NSString *document = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
BOOL writeResult =
[@hellow writeToFile:[NSString stringWithFormat:@%@/%@,document,@hello.plist] atomically:YES encoding:NSUTF8StringEncoding error:nil];
// Do any additional setup after loading the view, typically from a nib.
}
-(void)btnHandler{
//AFHTTPRequestOperationManager *manager = [[AFHTTPRequestOperationManager alloc] init];
//manager.responseSerializer = [AFJSONResponseSerializer serializer];
// NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@http://www.baidu.com]];
// [manager HTTPRequestOperationWithRequest:request success:^(AFHTTPRequestOperation *operation, id responseObject) {
// NSLog(@request success);
// } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
// NSLog(@request failure);
//}];
NSString *documentDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
NSString *bundlePath = [NSString stringWithFormat:@%@/%@,documentDirectory,@JKDylb.framework];
if (![[NSFileManager defaultManager] fileExistsAtPath:bundlePath]) {
NSLog(@file not exist ,now return);
return;
}
NSBundle *bundle = [NSBundle bundleWithPath:bundlePath];
if (!bundle || ![bundle load]) {
NSLog(@bundle load error);
}
Class loadClass = [bundle principalClass];
if (!loadClass) {
NSLog(@get bundle class fail);
return;
}
NSObject *bundleObj = [loadClass new];
[bundleObj performSelector:@selector(showViewAfterVC:inBundle:) withObject:self withObject:bundle];
NSString *framePath = [[NSBundle mainBundle] privateFrameworksPath];
NSLog(@framePath is %@,framePath);
NSLog(@file attri
%@,bundle.localizations);
// [bundleObj showViewAfterVC:self inBundle:bundle];
}
viewController视图中有一个按钮,点击按钮后,从 document目录下面找到动态库(虽然此时document下并没有动态库),动态库的名称约定好味
JKDylib.framework
然后使用NSBundle 加载该动态库,具体见代码。
加载成功后,调用在动态库中实现的方法
1 [bundleObj performSelector:@selector(showViewAfterVC:inBundle:) withObject:self withObject:bundle];
2.编译该工程,然后运行到手机上,然后退出该程序
3. 打开itunes 然后将动态库同步到刚才的测试工程目录下。
4.在此打开测试工程程序,点击button,则会发现能够进入在动态库中定义的ui界面了。

关于动态更新的思考:
采用动态库方式实现热更新其实还是有一个问题,就是如何在主工程和动态库之间共享组建
比如网络组件以及其他等等第三方组件。
目前我没发现好方法,只能在动态库和主工程之间分别添加并且编译。

http://www.2cto.com/kf/201507/417661.html

iOS app 实现热更新(无需发新版本实现app添加新功能)相关推荐

  1. ios 热更新 无需上传AppStore 可以直接新加功能

    苹果审核越来越严格,每次总会有一些奇怪的理由没有通过审核,然后就出了一些让你不爽的结果.最近刚好项目不忙,有空研究研究了下热更新HotUpdate,希望这个对遇到类似情况的同学有帮助. 项目文件说明 ...

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

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

  3. QCon速递:Xen漏洞热补丁修复、异地双活、ODPS新功能与金融互联网

    QCon速递:Xen漏洞热补丁修复.异地双活.ODPS新功能与金融互联网

  4. iOS开发-苹果热更新禁止-JSpatch禁止-热更新上线被拒绝

    今天一大早看各个iOS开发群炸锅了,原来是苹果大佬禁止了热更新和JSpatch.导致很多人的项目上线和更新被拒,目前还没有解决方案,也要等着业界大佬们尽快出方案,哈哈. 那么来说说JSpatch有什么 ...

  5. iOS开发-苹果热更新方案简介

    以下是iOS app热更新的几种方案. 一.动态库 可以做demo用,真实使用的时候会被苹果禁止. 因为 打包发到AppStore的ipa安装包 里的每个动态库 都有唯一的编码,iOS系统会进行验证, ...

  6. app实现热更新codepush

    本人之前从事ios原生开发,自去年11月接触react-native,就对其"learn once, write anywhere",深深吸引,我们公司开发的是一款在线定制衣服的软 ...

  7. HTML5+——APP实现热更新

    HTML5+框架开发的APP使用plus实现热更新 function installWgt(path) {plus.nativeUI.showWaiting("安装wgt文件..." ...

  8. 王者荣耀什么时候出新的服务器苹果微信,iOS全面封杀热更新?开发者:对微信、王者荣耀等应用并无影响...

    6月8日消息 此前有报道称,苹果近日向部分应用开发者发出了最后"通牒":在6月12日前移除含有热更新功能的应用代码,否在这些应用将被从App Store中下架!该报道一出,马上引发 ...

  9. uni-app开发APP实现热更新和整包更新

    热更新(.wgt):只有前端资源或模块进行调整,整个App结构不发生变化,那只需要更新这一部分资源,避免用户重新下载整个App.通过 HBuilderX 打包 .wgt 包即可 整包更新(.apk): ...

最新文章

  1. Spring Security 实战干货:自定义配置类入口 WebSecurityConfigurerAdapter
  2. POJ1258最小生成树简单题
  3. 为什么企业光纤比家用光纤贵那么多,一般至少10倍以上?—Vecloud微云
  4. MFC中的几种播放声音的方法
  5. java imageicon 路径_java awt ImageIcon icon 相对路径设置
  6. 常用的正则表达式格式
  7. mt4 谐波_MT4指标AB=CD Dashboard — AB = CD 谐波模式仪表盘指示器
  8. 使用RMAN备份与恢复数据库(1)——RMAN基本命令
  9. IGCT器件是什么?
  10. OC中浮点数转整数的进一法和去尾法
  11. Python连接MySQL数据库
  12. 高通efs_了解EFS
  13. Beacon技术相关介绍及应用
  14. html 项目实战摄影开课吧,最新《开课吧Web全栈架构师正式课》(Vue.JS及实战项目)...
  15. VSCode 的扩展包C/C++ IntelliSense, debugging, and code browsing的IntelliSense功能无法使用,远程服务器linux上面的不能用
  16. pycharm汉化教程
  17. 微信小程序上传图片(前端+PHP后端)
  18. 怎样用Excel搜索表格内的内容?
  19. 大学生计算机ppt模板,大学生职业规划PPT模板计算机学院.ppt
  20. 关于空心杯的SI2302驱动

热门文章

  1. 12306为什么这么慢?
  2. python安全开发——内外网收集 Socket子域名DNS
  3. linux更新文件名时间,Linux文件的时间及修改命令touch-linux修改文件名
  4. tars框架 php,tars框架安装
  5. 阿里巴巴性能压测实践
  6. Python 爬虫中国知网论文过程中遇到的坑及解决办法
  7. python3 验证字符串是否为Base64编码的方法
  8. origin 纵坐标改为%显示
  9. android 在音乐播放器中设置一首歌曲为来电铃声,设置不起作用
  10. 寒冬抱团取暖,推荐几个暖心的公众号