转自:xcode4.3下制作framework——(xcode4.2下也通用)
将自己的类封成库供别人调用,非常方便,就行xcode中的许多类库一样。那么如何制作自己的类库呢?
本人在网上看过很多童鞋的文章,都没有试成功,最后在同事的帮助下搞定。今天有点空闲时间,赶紧记下来,一是跟大家分享,二是怕忘了,今天有同事问我,都感觉有点生了,所以有了这篇文章。
下面教大家一步步制作framework
1、 新建一个项目选择Framwork&Library中的Cocoa Touch Static Library。如图
2、 命名项目名称
3、 加载自己要封装的东西
4、 加载自己的代码
5、 选择设备和模拟器两种方式,编译生成libhello_world.a文件
6、 查看是否生成两个文件
7、 选择Fill——>New——>Taget弹出界面选择Aggregate
8、 命名类库的名称
9、 选择Taget :HelloWorld的Bulid Phases选项卡
10、 添加Taget
11、 点击又下角Add Build Phase,选择Add Run Script。贴上这段脚本
xcodebuild -project ${PROJECT_NAME}.xcodeproj -sdk iphonesimulator -target ${PROJECT_NAME} -configuration ${CONFIGURATION} clean build
xcodebuild -project ${PROJECT_NAME}.xcodeproj -sdk iphoneos -target ${PROJECT_NAME} -configuration ${CONFIGURATION} clean build
12、 同样的方法添加另一个脚本,脚本的意思我没有研究,你可以详细看看
SIMULATOR_LIBRARY_PATH="${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/lib${PROJECT_NAME}.a" &&
DEVICE_LIBRARY_PATH="${BUILD_DIR}/${CONFIGURATION}-iphoneos/lib${PROJECT_NAME}.a" &&
UNIVERSAL_LIBRARY_DIR="${BUILD_DIR}/${CONFIGURATION}-iphoneuniversal" &&
UNIVERSAL_LIBRARY_PATH="${UNIVERSAL_LIBRARY_DIR}/${PRODUCT_NAME}" &&
FRAMEWORK="${UNIVERSAL_LIBRARY_DIR}/${PRODUCT_NAME}.framework" &&
# Create framework directory structure.
rm -rf "${FRAMEWORK}" &&
mkdir -p "${UNIVERSAL_LIBRARY_DIR}" &&
mkdir -p "${FRAMEWORK}/Versions/A/Headers" &&
mkdir -p "${FRAMEWORK}/Versions/A/Resources" &&
# Generate universal binary for the device and simulator.
lipo "${SIMULATOR_LIBRARY_PATH}" "${DEVICE_LIBRARY_PATH}" -create -output "${UNIVERSAL_LIBRARY_PATH}" &&
# Move files to appropriate locations in framework paths.
cp "${UNIVERSAL_LIBRARY_PATH}" "${FRAMEWORK}/Versions/A" &&
ln -s "A" "${FRAMEWORK}/Versions/Current" &&
ln -s "Versions/Current/Headers" "${FRAMEWORK}/Headers" &&
ln -s "Versions/Current/Resources" "${FRAMEWORK}/Resources" &&
ln -s "Versions/Current/${PRODUCT_NAME}" "${FRAMEWORK}/${PRODUCT_NAME}"
13、 点击右下角的Add Build Phase,选择Add Copy Files。在Destination选项中选择Absolute Path,在Subpath路径加载路径:${BUILD_DIR}/${CONFIGURATION}-iphoneuniversal/${PRODUCT_NAME}.framework/Versions/A/Headers
14、 点击“+按钮”,加载你要封装的.h文件
15、 选择Taget: HelloWorld进行编译
16、 然后选择libhello_world.a文件,右键选择Show in Finder。Debug-iphoneuniversal就是生成的framework。
17、 如果Headers文件夹里面为空,则把你封装的.h文件复制到里面,之后就可以在你的程序中使用了。
18、 至此framework制作完成,效果图:
Technical Q&A QA1490
Building Objective-C static libraries with categories
Q: Why do I get a runtime exception of "selector not recognized" when linking against an Objective-C static library that contains categories?
A: Why do I get a runtime exception of "selector not recognized" when linking against an Objective-C static library that contains categories?
The "selector not recognized" runtime exception occurs due to an issue between the implementation of standard UNIX static libraries, the linker and the dynamic nature of Objective-C. Objective-C does not define linker symbols for each function (or method, in Objective-C) - instead, linker symbols are only generated for each class. If you extend a pre-existing class with categories, the linker does not know to associate the object code of the core class implementation and the category implementation. This prevents objects created in the resulting application from responding to a selector that is defined in the category.
To resolve this issue, the target linking against the static library must pass the -ObjC option to the linker. This flag causes the linker to load every object file in the library that defines an Objective-C class or category. While this option will typically result in a larger executable (due to additional object code loaded into the application), it will allow the successful creation of effective Objective-C static libraries that contain categories on existing classes. Follow these steps to pass -ObjC to the linker:
- In Xcode, double-click the target's name under "Targets" in the Project window.
- Choose the Build pane from the ensuing Info window.
- Scroll down to the Other Linker Flags build setting under the Linking collection and set its value to -ObjC.
Figure 1 Target Build pane: Other Linker Flags
Important: For 64-bit and iPhone OS applications, there is a linker bug that prevents -ObjC from loading objects files from static libraries that contain only categories and no classes. The workaround is to use the -all_load or -force_load flags.
-all_load forces the linker to load all object files from every archive it sees, even those without Objective-C code. -force_load is available in Xcode 3.2 and later. It allows finer grain control of archive loading. Each -force_load option must be followed by a path to an archive, and every object file in that archive will be loaded.
Document Revision History
相关推荐
通过混淆ollvm,更改xcode编译方式。达到混淆目的。来过审ios4.3条款
密码保护
iphone开发基础教程是最受欢迎的iPhone开发书籍。 现在献上最新Xcode4.3版。
基于Xcode4.3的iPhone编程学习笔记 第一篇,HelloWorld;
基于Xcode4.3的iPhone编程学习笔记 第一篇 HelloWorld
系本人根据网上资料对xcode4.3进行破解后整理,花了两个小时整理该文档,分就多要点了。
xcode4.3 4.4_免证书开发调试并构建ipa.doc,网上教程的整理,我自己的是4.3已经测试通过
零基础,非常入门的好文档,适合对xcode完全无接触的纯新人学习。从界面认识掌握到应用常用到的基本功能实现。
xcode4.0.2sdk4.3 xcode4.0.2sdk4.3 xcode4.0.2sdk4.3xcode4.0.2sdk4.3
亲测,MAC 10.7 下xcode 4.3完美破解,可真机调试, MAC 10.8 下 xcode4.4 完美破解,可真机调试
Xcode13的XCTAutomationSupport.framework文件
下载好解压到这个目录: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport 重启Xcode。就可以真机调试啦。
xcode4.0.2andsdk4.3 在苹果官网可以下载 但速度就是龟速 4个多g 让人怎么用啊 不知道苹果怎么想的 这段时间我在网上找到了115网盘的下载地址,本人也是用这个地址下载的,要下载的要赶快啊,到期也就还有20多天了...
XCode 3.2.6 +iOS 4.3 SDK 官方下载地址连接,下载更安全,下载速度更快更稳定。
xcode 4.0.1 + ios sdk4.3
Xcode14的XCTAutomationSupport.framework文件
XCode 最新版本,集合iOS sdk 4.3
将FileProvider.framework和IOSurface.framework复制到文件夹,xcode8报缺失文件的那个路径
自己手把手实现IOS framework的创建以及在其它项目中引用(包括开发形式的引用),绝对有保证,有任何问题可咨询我351259738@qq.com
Xcode 4.1 and iOS SDK 4.3 GM BT 种子