ios framework制作流程

首先,新建一个framework项目,如下步骤

1.

.ios framework制作流程

2.

ios framework制作流程

然后修改Dead Code Stripping:NO,

            Link With Standard Libraries:NO

            Mach-O Type:Static Library

接下来新建一个类fwSayHi.m 并且添加一个res.bundle 内容如下图:

ios framework制作流程

在fw.h中导入所有需要引入的头文件,这样在使用framework的时候,只需要导入fw.h一个头文件就可以了。

下面要做的,就是在Build Phases :Headers 的public里面添加需要公开的头文件,儿private和project下面的头文件是无法被外部工程引入的。如图:


ios framework制作流程

最后,需要Aggregate一个target,run script 里写入角标如下:

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}"

这样,运行这个target就会生成framework了。