ios 不采用三方框架热更新

本文介绍了一种iOS应用中实现TabBarController热更新的方法。通过检查应用文档目录下的Framework文件来决定是否使用HotUpdateControl类进行页面控制器的加载。若未发现对应的Framework,则创建默认的导航控制器。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

核心功能在这里,其余步骤其实在另外一个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];  

}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值