只要審核通過后,無須再次審核,就可以動態(tài)更新,iOS有三種處理方案:
一、開源框架 reactive native,但是編程語言是js
二、lua 腳本
三、使用oc語言的動態(tài)庫framework。前兩者,我不打算細(xì)講,我主要介紹怎么用oc進(jìn)行熱更新
1、創(chuàng)建framework工程:
20151218142500375.jpeg
2、代碼處理:
20151218142629786.jpeg
寫一個(gè)controller的控制工具類:
//
//
// HotUpdateControl.m
// HotUpdateMudel
//
// Created by wukong on 15/12/18.
// Copyright ? 2015年 lhc. All rights reserved.
//
#import "HotUpdateControl.h"
#import "AController.h"
#import "BViewController.h"
#import "CViewController.h"
#import "DViewController.h"
#import "EViewController.h"
@implementation HotUpdateControl
-(NSArray *)getVcs {
return @[
[[AController alloc]init],
[[BViewController alloc]init],
[[CViewController alloc]init],
[[DViewController alloc]init],
[[EViewController alloc]init]];
}
@end
好了,開始打包framework,為了以免打包出來的framework,在真機(jī)上面運(yùn)行不了,我們使用一個(gè)腳本來進(jìn)行打包,目的是多型號CPU核心的合成,就是打出一個(gè)通用的包。
# Sets the target folders and the final framework product.
# 如果工程名稱和Framework的Target名稱不一樣的話,要自定義FMKNAME
# 例如: FMK_NAME = "MyFramework"
FMK_NAME=${PROJECT_NAME}
# Install dir will be the final output to the framework.
# The following line create it in the root folder of the current project.
INSTALL_DIR=${SRCROOT}/Products/${FMK_NAME}.framework
# Working dir will be deleted after the framework creation.
WRK_DIR=build
DEVICE_DIR=${WRK_DIR}/Release-iphoneos/${FMK_NAME}.framework
SIMULATOR_DIR=${WRK_DIR}/Release-iphonesimulator/${FMK_NAME}.framework
# -configuration ${CONFIGURATION}
# Clean and Building both architectures.
xcodebuild -configuration "Release" -target "${FMK_NAME}" -sdk iphoneos clean build
xcodebuild -configuration "Release" -target "${FMK_NAME}" -sdk iphonesimulator clean build
# Cleaning the oldest.
if [ -d "${INSTALL_DIR}" ]
then
rm -rf "${INSTALL_DIR}"
fi
mkdir -p "${INSTALL_DIR}"
cp -R "${DEVICE_DIR}/" "${INSTALL_DIR}/"
# Uses the Lipo Tool to merge both binary files (i386 + armv6/armv7) into one Universal final product.
lipo -create "${DEVICE_DIR}/${FMK_NAME}" "${SIMULATOR_DIR}/${FMK_NAME}" -output "${INSTALL_DIR}/${FMK_NAME}"
rm -r "${WRK_DIR}"
open "${INSTALL_DIR}"
20151218143348606.jpeg
20151218143558159.jpeg
3、建立一個(gè)主項(xiàng)目,就是使用這些動態(tài)庫的工程
現(xiàn)在進(jìn)行讀取離線包的測試,只要這個(gè)項(xiàng)目,能夠從沙箱里面讀取到代碼文件,就意味著可以在線更新代碼,遠(yuǎn)程升級!!!
20151218144015690.jpeg
動態(tài)庫已經(jīng)加載到了沙箱~~~
我修改了UITabBarController加載版塊的初始化方法,如果沙箱有framework動態(tài)庫,就加載framework動態(tài)庫上面的版塊,令到項(xiàng)目可以模塊化
//
// TabController.m
// HotUpdate
//
// Created by wukong on 15/12/18.
// Copyright ? 2015年 lhc. All rights reserved.
//
#import "TabController.h"
//#import <HotUpdateMudel/HotUpdateControl.h>
@interface TabController ()
@end
@implementation TabController
-(instancetype)initWithCoder:(NSCoder *)aDecoder{
if (self = [super initWithCoder:aDecoder]) {
NSString *documentDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
NSArray* arrFramework = [self getFilenamelistOfType:@"framework" fromDirPath:documentDirectory];
NSLog(@"%@",arrFramework);
if (arrFramework.count==0) {
NSArray * arrTitle = @[@"首頁",@"廣場",@"朋友圈",@"我的",@"設(shè)置"];
NSMutableArray * arrVcs = @[].mutableCopy;
for (int i=0; i<arrTitle.count; i++) {
UIViewController * vcRoot = [[UIViewController alloc]init];
vcRoot.title = arrTitle[i];
vcRoot.view.backgroundColor = [UIColor whiteColor];
UINavigationController * navi = [[UINavigationController alloc]initWithRootViewController:vcRoot];
[arrVcs addObject:navi];
}
[self setViewControllers:arrVcs animated:YES];
}else{
NSString *bundlePath = [NSString stringWithFormat:@"%@/%@",documentDirectory,[arrFramework lastObject]];
if (![[NSFileManager defaultManager] fileExistsAtPath:bundlePath]) {
NSLog(@"file not exist ,now return");
return self;
}
NSBundle *bundle = [NSBundle bundleWithPath:bundlePath];
if (!bundle || ![bundle load]) {
NSLog(@"bundle load error");
}
Class loadClass = [bundle classNamed:@"HotUpdateControl"];
if (!loadClass) {
NSLog(@"get bundle class fail");
return self;
}
NSObject *bundleObj = [loadClass new];
NSArray * arrVc = [bundleObj performSelector:@selector(getVcs)];
NSMutableArray * arrVcs = @[].mutableCopy;
for (int i=0; i<arrVc.count; i++) {
UIViewController * vcRoot =arrVc[i];
vcRoot.view.backgroundColor = [UIColor whiteColor];
UINavigationController * navi = [[UINavigationController alloc]initWithRootViewController:vcRoot];
[arrVcs addObject:navi];
}
[self setViewControllers:arrVcs animated:YES];
}
}
return self;
}
-(NSArray *) getFilenamelistOfType:(NSString *)type fromDirPath:(NSString *)dirPath
{
NSArray *fileList = [[[NSFileManager defaultManager] contentsOfDirectoryAtPath:dirPath error:nil]
pathsMatchingExtensions:[NSArray arrayWithObject:type]];
return fileList;
}
- (void)viewDidLoad {
[super viewDidLoad];
}
@end
看結(jié)果了,如果是本地的默認(rèn)版本,應(yīng)該是
@[@"首頁",@"廣場",@"朋友圈",@"我的",@"設(shè)置"];的模塊
但是如果是沙箱里面的模塊
那么久應(yīng)該ABCDE
20151218144417068.jpeg
good luck
轉(zhuǎn)自IOS 熱更新,實(shí)時(shí)代碼更新,動態(tài)更新,動態(tài)庫framework