0. 参考

  http://www.cocoachina.com/industry/20140613/8810.html

  framework+xib参考 : http://blog.csdn.net/xyxjn/article/details/42527341

1. 设置主头文件

  系统已经自动生成好了。

2. 设置公开的头文件

  工程导航栏>"工程名">Build Phases>菜单栏Editor>Add Build Phases>Add Headers Build Phase。

  如果该项不能选择,则点击下方的Build Phases的区域获取焦点。其它需要公开的头文件就放到Public下面。

3. 编译后就生成了framework

4. 合并模拟器framework和真机framework

  iOS默认生成两个framework,一个用于模拟器,一个用于真机。这样的话,用起来模拟器和真机可能会表现不一定。所以,合并成通用的framework是很好的方案。并且这是可行的。合并完了之后呢,顺便要把生成的framework放到工程的制定Products目录下。因为Products名称是生成的默认目录名称。

  怎么进行合并呢?

4.1. 创建Aggregate Target

4.1.0. 参考

iOS 之 Aggregate Target,在这里我取名为:aggregateTest

4.1.1. 设置Target Dependencies

  TARGETS-->选中“aggregateTest”-->Build Phases-->Target Dependencies  ,将真正的动态库添加到其中。

4.2. 脚本

4.2.1. 目的

  • 分别编译生成真机和模拟器使用的framework;
  • 使用lipo命令将其合并成一个通用framework;
  • 最后将生成的通用framework放置在工程根目录下新建的Products目录下。

4.2.2. 路径

  TARGETS-->选中“aggregateTest”-->Build Phases-->Run Script-->左上角+-->New Run Script Phase

4.2.3. 内容

# Sets the target folders and the final framework product.
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 "${SRCROOT}/Products/"

4.2.4. 生成

  在Xcode的左上角选中刚生成的Aggregate>Generic iOS Device ,编译。如果,编译很快,则表示没有成功,因为输入的脚本没有执行。则切换文件失去焦点,让脚本有效,或者重新打开工程。

4.3. 使用动态库

4.3.1. 添加动态库到工程

4.3.1.1. Link Binary with Libraries

  项目导航栏-->选中项目-->Targets-->选中项目-->Build Phases-->Link Binary with Libraries

4.3.1.2. Copy Bundle Resources

  项目导航栏-->选中项目-->Targets-->选中项目-->Build Phases-->Copy Bundle Resources

  如果还不行,就需要:

  项目导航栏-->选中项目-->Targets-->选中项目-->General --> embeded Binaries

4.3.1.3. 为动态库添加链接依赖
4.3.1.3.1. 自动链接依赖

  启动时自动链接:项目导航栏-->选中项目-->Targets-->选中项目-->Build Setting-->Runpath Search Paths,添加@executable_path/

  由于Copy Bundle Resources有动态库,即在main bundle(即沙盒中的.app目录)里面有动态库,所以,添加@executable_path/,表示可执行文件所在目录。

4.3.1.3.1. 需要时链接依赖

  即插即用,需要时再加载动态库。如果是这种方式,那么需要把Targets-->Build Phases-->Link Binary With Libraries中的动态库的Status由Required设置为Optional,或者直接删除也行。

4.3.1.4. 加载动态库
4.3.1.4.1. dlopen 加载
- (IBAction)onDlopenLoadAtPathAction1:(id)sender
{
NSString *documentsPath = [NSString stringWithFormat:@"%@/Documents/xxx.framework/Dylib",NSHomeDirectory()];
[self dlopenLoadDylibWithPath:documentsPath];
} - (void)dlopenLoadDylibWithPath:(NSString *)path
{
libHandle = NULL;
libHandle = dlopen([path cStringUsingEncoding:NSUTF8StringEncoding], RTLD_NOW);
if (libHandle == NULL) {
char *error = dlerror();
NSLog(@"dlopen error: %s", error);
} else {
NSLog(@"dlopen load framework success.");
}
}

  该方式不知道会否通过苹果审核,建议不要使用。

4.3.1.4.1. NSBundle 加载
- (IBAction)onBundleLoadAtPathAction1:(id)sender
{
NSString *documentsPath = [NSString stringWithFormat:@"%@/Documents/Dylib.framework",NSHomeDirectory()];
[self bundleLoadDylibWithPath:documentsPath];
} - (void)bundleLoadDylibWithPath:(NSString *)path
{
_libPath = path;
NSError *err = nil;
NSBundle *bundle = [NSBundle bundleWithPath:path];
if ([bundle loadAndReturnError:&err]) {
NSLog(@"bundle load framework success.");
} else {
NSLog(@"bundle load framework err:%@",err);
}
}
4.3.1.4. 使用动态库的功能

  加载完成后声明类就可以使用了,操作示例如下:

Class rootClass = NSClassFromString(@"Person"); 

if (rootClass) {
id object = [[rootClass alloc] init];
[(Person *)object run];
}

4.3. 监控动态库的加载和移除

_dyld_register_func_for_add_image(&image_added);
_dyld_register_func_for_remove_image(&image_removed);

5. 其它

5.1. framework 里面的资源

资源放置在 Aggregate->Build Phases ->Target Dependencies

引用资源类似这样:VoogolfZxing.framework/CodeScan.bundle/qrcode_Scan_weixin_Line

iOS 开发新版 动态库framework的更多相关文章

  1. ios 开发中 动态库 与静态库的区别

    使用静态库的好处 1,模块化,分工合作 2,避免少量改动经常导致大量的重复编译连接 3,也可以重用,注意不是共享使用 动态库使用有如下好处: 1使用动态库,可以将最终可执行文件体积缩小 2使用动态库, ...

  2. iOS开发中静态库之".framework静态库"的制作及使用篇

    iOS开发中静态库之".framework静态库"的制作及使用篇 .framework静态库支持OC和swift .a静态库如何制作可参照上一篇: iOS开发中静态库之" ...

  3. WWDC2014之iOS使用动态库 framework【转】

    from:http://www.cocoachina.com/industry/20140613/8810.html JUN 12TH, 2014 苹果的开放态度 WWDC2014上发布的Xcode6 ...

  4. iOS开发之静态库(五)—— 图片、界面xib等资源文件封装到静态框架framework

    编译环境:Macbook Air + OS X 10.9.2 + XCode5.1 + iPhone5s(iOS7.0.3) 一.首先将资源文件打包成bundle 由于bundle是静态的,所以可以将 ...

  5. iOS开发中静态库制作 之.a静态库制作及使用篇

    iOS开发中静态库之".a静态库"的制作及使用篇 一.库的简介 1.什么是库? 库是程序代码的集合,是共享程序代码的一种方式 2.库的类型? 根据源代码的公开情况,库可以分为2种类 ...

  6. iOS开发中与库相关的术语

    动态库 VS 静态库 Static frameworks are linked at compile time. Dynamic frameworks are linked at runtime

  7. 分享:写了一个 java 调用 C语言 开发的动态库的范例

    分享:写了一个 java 调用 C语言 开发的动态库的范例 cfunction.h   代码#pragma once#ifdef __cplusplusextern "C" {#e ...

  8. 李洪强iOS开发之静态库的打包一

    李洪强iOS开发之静态库的打包一 //静态库一般做一下几种事情 //1 工具类 算法逻辑 新建工具类LHQTools 定义类方法 + (NSInteger)sumWithNum1: (NSIntege ...

  9. 李洪强iOS开发之动态获取UILabel的bounds

    李洪强iOS开发之动态获取UILabel的bounds 在使用UILabel存放字符串时,经常需要获取label的长宽数据,本文列出了部分常用的计算方法. 1.获取宽度,获取字符串不折行单行显示时所需 ...

随机推荐

  1. Binary Watch

    Binary Watch 描述 Consider a binary watch with 5 binary digits to display hours (00 - 23) and 6 binary ...

  2. Linux Mint 17.2个性化配置

    一.开启root 帐号登陆 设置一个口令,使用: sudo passwd root 当你使用完毕后屏蔽root帐号使用以下命令锁定root帐号 : sudo passwd -l root 如何在终端模 ...

  3. Nested weights are bad for performance

    警告信息“Nested weights are bad for performance”的消除方法 原因分析:在布局进行嵌套使用时,父布局与子布局都使用了android:layout_weight,但 ...

  4. Sublime Text 3 搭建 Golang 开发环境

    安装Golang go语言主页: https://golang.org/ go语言安装下载: https://golang.org/dl 环境变量设置: GOROOT: GOROOT变量设置go安装的 ...

  5. 织梦网站底部的Power by DedeCms怎么去掉?

    由于织梦DEDECMS程序6月份的漏洞,很多织梦网站都被黑了,所以大家都在抓紧时间更新系统补丁.但是这次的DEDECMS V5.7版本更新后,在前台网页底部会出现织梦版权信息 “powered by ...

  6. DHCP配置部分

    1.DHCP工作过程 dhcp discover \\客户端请求服务器器提供地址 dhcp offer \\服务器提供ip地址 dhcp request \\客户端租用ip地址 dhcp ack \\ ...

  7. Clustering text documents using k-means

    源代码的链接为http://scikit-learn.org/stable/auto_examples/text/document_clustering.html Loading 20 newsgro ...

  8. 打印等腰三角形as3

    package { import flash.display.Sprite; public class san extends Sprite { public function san() { var ...

  9. webservice中采用协议Http,它是指什么意思

    webservice 协议 Web Service使用的是 SOAP (Simple Object Access Protocol)协议soap协议只是用来封装消息用的.封装后的消息你可以通过各种已有 ...

  10. iOS中正则表达式的三种使用方式

    1.利用NSPredicate(谓词)匹配 例如匹配有效邮箱: NSString *email = @“nijino_saki@163.com”: NSString *regex = @"[ ...