眼下可以实现热更新的方法,总结起来有下面三种

1. 使用FaceBook 的开源框架 reactive native,使用js写原生的ios应用

ios app能够在执行时从server拉取最新的js文件到本地。然后执行,由于js是一门动态的

脚本语言。所以可以在执行时直接读取js文件执行,也因此可以实现ios的热更新

2. 使用lua 脚本。lua脚本如同js 一样,也能在动态时被。之前愤慨的小鸟使用

lua脚本做的一个插件 wax,能够实现使用lua写ios应用。热更新时,从server拉去lua脚本

然后动态的运行就能够了。遗憾的是 wax眼下已经不更新了。

上面是网上如今可以搜到的热更新方法。

xcode 6 之后,苹果开放了 ios 的动态库编译权限。所谓的动态库。事实上就是能够在执行时载入。

正好利用这一个特性,用来做ios的热更新。

1.

建立一个动态库。如图:

动态库包括须要使用的viewCOntroller,当然能够包括不论什么须要使用的自己定义ui和逻辑。

动态库的入口是一个jkDylib的类。它的.h和.m文件分别例如以下:

//
// JKDylib.h
// JKDylb
//
// Created by wangdan on 15/7/5.
// Copyright (c) 2015年 wangdan. All rights reserved.
// #import <Foundation/Foundation.h> @interface JKDylib : NSObject -(void)showViewAfterVC:(id)fromVc inBundle:(NSBundle*)bundle; @end

.m文件

//
// JKDylib.m
// JKDylb
//
// Created by wangdan on 15/7/5.
// Copyright (c) 2015年 wangdan. All rights reserved.
// #import "JKDylib.h"
#import "JKViewController.h" @implementation JKDylib -(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

上述代码意图很明显,

就是调用该动态库的时候

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

在该函数中,创建一个viewController 然后使用mainBundler 的navigationController  push 新建的viewController,显示动态库的ui界面。

而动态库中的JKViewController 内容则能够依据须要随便定义。

2. 完毕上述动态库的编译工作后,如今须要做的就是在主project中。写一段载入该动态库的代码。

主project文件夹例如以下:

在最重要的viewCotrooler里面,定义了载入动态库的方法:

//
// ViewController.m
// DylibTest
//
// Created by wangdan on 15/7/5.
// Copyright (c) 2015年 wangdan. All rights reserved.
// #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 \n %@",bundle.localizations); // [bundleObj showViewAfterVC:self inBundle:bundle];
} - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} @end

viewController视图中有一个button,点击button后,从 document文件夹以下找到动态库(尽管此时document下并没有动态库),动态库的名称约定好味

JKDylib.framework

然后使用NSBundle 载入该动态库,详细见代码。

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

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

编译该project。然后执行到手机上,然后退出该程序

3. 打开itunes 然后将动态库同步到刚才的測试project文件夹下。

4.在此打开測试project程序。点击button,则会发现可以进入在动态库中定义的ui界面了。

上面project的參考代码 在

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

关于动态更新的思考:

採用动态库方式实现热更新事实上还是有一个问题。就是怎样在主project和动态库之间共享组建

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

眼下我没发现好方法,仅仅能在动态库和主project之间分别加入而且编译。

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

  1. ios app 实现热更新(无需发新版本实现app添加新功能)

    目前能够实现热更新的方法,总结起来有以下三种 1. 使用FaceBook 的开源框架 reactive native,使用js写原生的iOS应用 ios app可以在运行时从服务器拉取最新的js文件到 ...

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

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

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

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

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

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

  5. Unity3D热更新之LuaFramework篇[08]--热更新原理及热更服务器搭建

    前言 前面铺垫了这么久,终于要开始写热更新了. Unity游戏热更新包含两个方面,一个是资源的更新,一个是脚本的更新. 资源更新是Unity本来就支持的,在各大平台也都能用.而脚本的热更新在iOS平台 ...

  6. 🙈 如何隐藏你的热更新 bundle 文件?

    如果你喜欢我写的文章,可以把我的公众号设为星标 ,这样每次有更新就可以及时推送给你啦. 前段时间我们公司的一个大佬从一些渠道得知了一些小道消息,某国民级 APP 因为 Apple App Store ...

  7. 轻松理解webpack热更新原理

    一.前言 - webpack热更新 Hot Module Replacement,简称HMR,无需完全刷新整个页面的同时,更新模块.HMR的好处,在日常开发工作中体会颇深:节省宝贵的开发时间.提升开发 ...

  8. react-native热更新之CodePush详细介绍及使用方法

    react-native热更新之CodePush详细介绍及使用方法 2018年03月04日 17:03:21 clf_programing 阅读数:7979 标签: react native热更新co ...

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

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

随机推荐

  1. C# 特性(Attribute)(二)

    AttributeUsage类是另外一个预定义特性类,它帮助我们控制我们自己的定制特性的使用.它描述了一个定制特性如和被使用.    AttributeUsage有三个属性,我们可以把它放置在定制属性 ...

  2. Spark踩坑记:共享变量

    收录待用,修改转载已取得腾讯云授权 前言 前面总结的几篇spark踩坑博文中,我总结了自己在使用spark过程当中踩过的一些坑和经验.我们知道Spark是多机器集群部署的,分为Driver/Maste ...

  3. 25个iptables常用示例

    本文将给出25个iptables常用规则示例,这些例子为您提供了些基本的模板,您可以根据特定需求对其进行修改调整以达到期望. 格式 iptables [-t 表名] 选项 [链名] [条件] [-j ...

  4. typescript 的一种引入文件的方式 Triple-Slash Directives

    ---恢复内容开始--- /// reference 原文: https://www.typescriptlang.org/docs/handbook/triple-slash-directives. ...

  5. 【转】Understanding the Angular Boot Process

    原文: https://medium.com/@coderonfleek/understanding-the-angular-boot-process-9a338b06248c ----------- ...

  6. KETTLE6.0版本体验小结

    不知不觉Kettle以及到了6.0,名字似乎也变了Pentaho官方的名称是 Pentaho  Data Integration,于是就下载了最新的版本,下载地址为: Pentaho Data Int ...

  7. 【Nodejs】“快算24”扑克牌游戏算法 1.01

    考虑到1.00版本需要改源码变更四个数字,这版修改了一下变成控制台输入了. 先把两个数四则运算得到结果想清楚就是C2代码,三个数就是C3,四个数就是C4.简单的代码简单,却是复杂的基础:复杂的脱胎于简 ...

  8. 在Foreda8上安装libaio-0.3.105-2.i386.rpm

    libaio-0.3.105-2.i386.rpm是安装MySql必须的包,可以从这里下载:http://pan.baidu.com/share/link?shareid=2348086735& ...

  9. 大型应用的javascript架构

    来源:http://blog.leezhong.com/tech/2010/11/29/javascript-arch.html 目前很多网站基本没有明确的前端架构,大多是服务端渲染视图页,输出到浏览 ...

  10. APUE读书笔记-第15章-进程间通信

    15.1 引言 *进程之间交换信息的方法可以经由fork或exec传送打开文件,或者通过文件系统 *进程之间相互通信的其他技术——IPC(InterProcess Communication)包括半双 ...