您的位置:首页 > 移动开发 > IOS开发

ios 不采用三方框架热更新

2017-03-05 22:32 211 查看
核心功能在这里,其余步骤其实在另外一个FrameWorks工程,那边做的事情就是建立了一个HotUpdateControl对象 内部有一个方法getVcs 可以返回一个UIViewController数组

#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 = @[@"首页",@"广场",@"朋友圈",@"我的",@"设置"];
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];

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  ios 热更新 OC