1、创建workspace
两张图搞定的事情,就不写了。
① 打开Xcode,左上角 File--> New --> Workspace.

② 创建一个文件夹,用来存放我们生成的文件,成功之后如下。

2、创建SDK
也是,我们几张图来搞定
① Xcode左上角 File -> New -> Project.

② 点击 Cocoa Touch Framework.

③ 输入SDK名字。

④ 选择group选项;


⑤ 创建完成。


3、创建Demo
其实都感觉这一部分应该不要的,但是删了又感觉少了什么
① 是不是很熟悉;

② 注意下面的group和addto

③ 创建成功之后如下。


4、Demo关联SDK
4.1.1 把SDK打包成framework(方法一)
① SDK中创建一个Cat类,等下要用到。


② 把生成的类放到public里边,这样的话才能引用。




③ 注意,接下来的命令行我们用到的是 TGTestSDK.framework 里边的 TGTestSDK 。用命令行 lipo -create (真机路径) (模拟器路径) -output (生成文件路径)

④ 然后替换掉.framework文件下的 TGTestSDK 文件,这个.framework 文件就是我们要的。
4.1.2 把SDK打包成framework(方法二)
① 方法二要相比方法一更简单一些,先按照步骤生成一个 File -> New -> Target -> Aggregate 文件,




② 把下面这段话复制粘贴进去,然后command+B
编译一下,再把.framework文件用 show in Finder
找到,拖进项目 TGTestDemo 就可以直接用。
注意,格式千万千万千万不要错,不然会出问题。
注意,编译的时候千万选对如图。

# Sets the target folders and the final framework product.
# 如果工程名称和Framework的Target名称不一样的话,要自定义FMKNAME
# 例如: FMK_NAME = "MyFramework"
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 "${INSTALL_DIR}"
4.2 Demo与SDK关联
① 把生成的framework拖进项目里边,然后就可以使用了

② 这里可以正常运行,但是报了个警告

③ 这个是需要在 TGTestSDK.h 里边把公开的头文件要引用一下,"Missing submodule '********'"的警告就会消失了


好了,一个简单的SDK已经做好,大家可以在此基础上发挥了,带有图片资源的话,把图片打包成Bundle文件,和framework文件一起拷贝到项目中即可。
网友评论