framework 工程搭建

1. 创建workspace

2. 创建framework工程

3. 创建Demo工程

4. 创建成功

5. 设置SDK工程配置

6. 设置Headers,将要公开的头文件拖到Public下,要隐藏的放到Private或Project下,隐藏的头文件不能被引用,效果图: 

7. 创建一个Aggregare

选中SDK工程->Editor->Add Target

8. 嵌入脚本,选中刚刚创建的Aggregare,然后选中右侧的Build Phases,点击左边的+号,选择New Run Script Phases

9. 下面把这段脚本复制进去(格式不要错,格式错编译不通过)

# Type a script or drag a script file from your workspace to insert its path.

# 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 build

xcodebuild -configuration "Debug" -target "${FMK_NAME}" -sdk iphonesimulator 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}"

 

10. 编译command + B,编译通过在finder中找到framework,拷贝出来。

11. SHTestDemo与SHTestSDK的关联,把打包好的framework拖到demo里面,注意:以上功能就是SDK 和 demo 相关联好了

12. SHTestSDK 调试,修改SDK中的代码,运行demo就是修改后的效果,然后就可以愉快的在这个工程里面开发调试SDK了。

13. framework加载图片只能从bundl中加载图片,所以需要新建一个bundle项目 

14. bundle工程配置,因为Bundle默认是macOS系统的,所以我们要修改他的属性,修改成iOS系统。

修改Build Setting中COMBINE_HIDPI_IMAGES属性为NO。否则Bundle图片格式就会为tiff格式。

作为资源包只需要编译就好,不需要安装相关配置,设置Skip Install的值为YES,同时删除Installation Directory的值

把图片拉进Bundle中,选择真机模式,command + B,右键Show in Finder,可以看到我们生成的Bundle文件。

把Bundle文件导入到我们的framework中,我们用到图片的时候,就取Bundle中的图片来用。使用时注意,具体用法👇

 

 

 

 

 

posted @ 2019-07-25 11:57  do+better  阅读(321)  评论(0编辑  收藏  举报