1 当前模拟器设备 app的Documents 路径(沙盒);
NSString *path = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES) objectAtIndex:0];
2 动态加载代码:
//查找framwork路径
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES) ;
if (paths.count > 0){
NSString *documentPath = paths[0];
NSString *libName = @"/FrameworkDemo.framework";
NSString *libPath = [documentPath stringByAppendingString:libName];
NSFileManager *manager = [NSFileManager defaultManager];
if ([manager fileExistsAtPath:libPath]) {
NSLog(@"%@ path:%@",libName,libPath);
//bundle加载动态库
NSBundle *frameBundle = [NSBundle bundleWithPath:libPath];
if (frameBundle && [frameBundle load]) {
NSLog(@"success");
Class testClass = NSClassFromString(@"TestM");
if (testClass) {
//调用动态库方法
[testClass performSelector:@selector(test)];
}
}
}else{
NSLog(@"路径中的文件不存在");
}
}
输出:framwork的TestM类的test方法的打印内容;
三 framework热更新:
如果不上架appstore,可以通过framework实现热更新,要上架则不能通过审核,不然苹果审核不了你真正上线用的framework版本;