iOS实时发版,动态库方式 不上App Store可以使用啊
来源:互联网 发布:ai软件工具栏不见了 编辑:程序博客网 时间:2024/05/18 18:00
m
iOS如果想要实现实时发版,据我了解现在基本上用的是两种方式
1:使用Lua脚本进行,基本上很多手游都是这样做的,再配合上Cocos2d-x这个框架使用起来也比较简单。
2:使用动态库 这里我说的就是这中方式。
先说下实现思路,在动态库中实现一个入口类,和入口方法,这个方法在主工程中调用
这里说下创建动态库的步骤:
下面直接上代码啦。
动态库中测试界面
VCOne.h
123456#
import
<uikit uikit.h=
""
>
@interface
VCOne :UIViewController
@property
(retain, nonatomic) NSBundle *root_bundle;
//保存framework的路径
@end
</uikit>
VCOne.m123456789101112131415- (
void
) viewDidLoad
{
[
super
viewDidLoad];
UILabel * label1 = [[UILabel alloc] initWithFrame:CGRectMake(
0
,
0
, self.view.frame.size.width,
50
)];
label1.text = @第一个视图;
[self.view addSubview:label1];
self.view.backgroundColor = [UIColor whiteColor];
UIImageView *image = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[_root_bundle pathForResource:
@changmen
ofType:
@jpg
]]];
image.frame = CGRectMake(
100
,
100
,
300
,
300
);
[self.view addSubview:image];
}
下面介绍与主工程交互的入口类。FrameWorkStart.h
1234567891011#
import
<foundation foundation.h=
""
>
@interface
FrameWorkStart : NSObject
/*
* 主程序和此动态库的关系枢纽,也就是从“主程序”到“动态库内封装的程序”的入口方法
*/
- (
void
) startWithObject:(id)object withBundle:(NSBundle *)bundle;
@end
</foundation>
FrameWorkStart.m123456789101112131415161718192021222324252627#
import
FrameWorkStart.h
#
import
VCOne.h
@implementation
FrameWorkStart
- (
void
) startWithObject:(id)object withBundle:(NSBundle *)bundle
{
/*
*初始化第一个controller
*这里的重点是资源文件的加载
通常我们在初始化的时候并不是很在意bundle:这个参数,
其实我们所用到的图片、xib等资源文件都是在程序内部中获取的,也就是我们常用的[NSBundle mainBundle]中获取,所谓的NSBundle本质上就是一个路径,mainBundle指向的是.app下。
而如果我们不指定bundle,则会默认从.app路径下去寻找资源。
不过很显然,我们的动态库是放到“主程序”的document文件下的,所以资源文件是不可能在[NSbundle mainBundle]中获取到的,所以这里我们需要指定bundle参数,这也是传递framework的路径的意义所在
*/
VCOne *vcone = [[VCOne alloc] init];
vcone.root_bundle = bundle;
//转换传递过来的mainCon参数,实现界面跳转
UIViewController *viewCon = (UIViewController *)object;
[viewCon presentViewController:vcone animated:YES completion:^{
NSLog(@跳转到动态更新模块成功!);
}];
}
下面是主工程,当然就是创建的普通的iOS工程ViewController.m
将动态库的工程编译一下,放入主工程的document的目录下12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576#
import
ViewController.h
@interface
ViewController ()
@end
@implementation
ViewController
- (
void
)viewDidLoad {
[
super
viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
UIButton * btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
btn.frame = CGRectMake(
30
,
30
,
100
,
50
);
[btn setTitle:@测试动态库 forState:UIControlStateNormal];
[btn addTarget:self action:
@selector
(test) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btn];
}
- (
void
) test
{
NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
NSString *documentDirectory = nil;
if
([paths count] !=
0
)
documentDirectory = [paths objectAtIndex:
0
];
NSLog(
@documentDirectory
= %@,documentDirectory);
//拼接我们放到document中的framework路径
NSString *libName =
@Test1
.framework;
NSString *destLibPath = [documentDirectory stringByAppendingPathComponent:libName];
//判断一下有没有这个文件的存在 如果没有直接跳出
NSFileManager *manager = [NSFileManager defaultManager];
if
(![manager fileExistsAtPath:destLibPath]) {
NSLog(
@There
isn't have the file);
return
;
}
//复制到程序中
NSError *error = nil;
//加载方式二:使用NSBundle加载动态库
NSBundle *frameworkBundle = [NSBundle bundleWithPath:destLibPath];
if
(frameworkBundle && [frameworkBundle load]) {
NSLog(
@bundle
load framework success.);
}
else
{
NSLog(
@bundle
load framework err:%@,error);
return
;
}
/*
*通过NSClassFromString方式读取类
*FrameWorkStart 为动态库中入口类
*/
Class pacteraClass = NSClassFromString(
@FrameWorkStart
);
if
(!pacteraClass) {
NSLog(
@Unable
to get TestDylib
class
);
return
;
}
/*
*初始化方式采用下面的形式
alloc init的形式是行不通的
同样,直接使用PacteraFramework类初始化也是不正确的
*通过- (id)performSelector:(SEL)aSelector withObject:(id)object1 withObject:(id)object2;
方法调用入口方法(startWithObject:withBundle:),并传递参数(withObject:self withObject:frameworkBundle)
*/
NSObject *pacteraObject = [pacteraClass
new
];
[pacteraObject performSelector:
@selector
(startWithObject:withBundle:) withObject:self withObject:frameworkBundle];
}
这里在记录下如果找到编译出来的静态库。
0 0
- iOS实时发版,动态库方式 不上App Store可以使用啊
- iOS实时发版,动态库方式 不上App Store可以使用啊
- iOS 使用动态库(注意:提交App Store会被拒绝)
- iOS后台保持连接,使用VOIP Socket方式,上传App Store会被拒绝么?
- iOS在App Store上显示app副标题
- iOS-app store 的应用下架,这个下架的应用名称 多久后才可以使用?
- IOS APP 使用别人的P12文件上传APP store
- 不通过App Store,在iOS设备上直接安装应用程序
- 不通过App Store,在iOS设备上直接安装应用程序
- 不通过App Store,在iOS设备上直接安装应用程序
- 不通过App Store,在iOS设备上直接安装应用程序
- 不通过App Store,在iOS设备上直接安装应用程序
- 不通过App Store,在iOS设备上直接安装应用程序
- 不通过App Store,在iOS设备上直接安装应用程序
- iOS证书申请到应用上APP Store的流程
- 不通过App Store,在iOS设备上直接安装应用程序
- 不通过App Store,在iOS设备上直接安装应用程序
- IOS发布APP Store
- [翻译]MySQL5.0用户手册——第三章:快速入门
- win7下面怎么安装Active Directory
- 欢迎使用CSDN-markdown编辑器
- 当idea中properties配置文件中文显示utf8编码时
- Chromium Embedded Framework 3
- iOS实时发版,动态库方式 不上App Store可以使用啊
- C++基本数据类型和内存映像(1)
- 【剑指offer系列】 二维数组中的查找___3
- C# 微软开源专区
- 利用Qemu Guest Agent (Qemu-ga) 实现 Openstack 监控平台
- Web前端框架与类库的思考
- 实现runnable接口创建多现场
- SQL注入
- [翻译]MySQL5.0用户手册——第三章:快速入门