iOS Framework 的制作和特殊情况应用

故事的开端:

今天研究 PLCrashReporter 的时候,试着想把内部的源码打包 framework,试着扣出核心代码,结果失败,后来在想,能不能在我的 framework 里面包含 PLCrashReporterframework呢,然后就去研究了,一直在失败,结果我搜 PLCrashReporter的时候,发现 hockeyapp 也在内部使用了,然后试着研究了 OneAPM, 蒲公英 SDK,Newrelic 等内部都使用到了,但是实在不知道他们是怎么内置的.然后研究了一个下午 + 晚上终于搞定

过程,废话不多说,直接开搞

新建文件

iOS Framework 的制作和特殊情况应用_第1张图片
Paste_Image.png

这里随便写啦,记录详细点

iOS Framework 的制作和特殊情况应用_第2张图片
Paste_Image.png

新建完成是这样子滴☺️

iOS Framework 的制作和特殊情况应用_第3张图片
Paste_Image.png

把 Demo.h 这个文件删除,导入自己想要的 Framework 文件

iOS Framework 的制作和特殊情况应用_第4张图片
Paste_Image.png

下面添加一个这个,看图

iOS Framework 的制作和特殊情况应用_第5张图片
Paste_Image.png

搜索 other link

iOS Framework 的制作和特殊情况应用_第6张图片
Paste_Image.png

最好把 UIKit 也包含进去了

$(inherited)   -framework   CrashReporter  -framework  UIKit
iOS Framework 的制作和特殊情况应用_第7张图片
y

注意是这里!!!!也要这么搞

iOS Framework 的制作和特殊情况应用_第8张图片
Paste_Image.png

然后这里选择你想要暴露出去的文件

iOS Framework 的制作和特殊情况应用_第9张图片
Paste_Image.png

然后下面配置一下脚本

iOS Framework 的制作和特殊情况应用_第10张图片
Paste_Image.png

DEBUG 脚本

# 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=buildDEVICE_DIR=${WRK_DIR}/Debug-iphoneos/${FMK_NAME}.frameworkSIMULATOR_DIR=${WRK_DIR}/Debug-iphonesimulator/${FMK_NAME}.framework# -configuration ${CONFIGURATION}# Clean and Building both architectures.xcodebuild -configuration "Debug" -target "${FMK_NAME}" -sdk iphoneos -arch armv7 -arch armv7s -arch arm64 clean buildxcodebuild -configuration "Debug" -target "${FMK_NAME}" -sdk iphonesimulator -arch x86_64 clean build# Cleaning the oldest.if [ -d "${INSTALL_DIR}" ]thenrm -rf "${INSTALL_DIR}"fimkdir -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/"

Release 脚本

# 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=buildDEVICE_DIR=${WRK_DIR}/Release-iphoneos/${FMK_NAME}.frameworkSIMULATOR_DIR=${WRK_DIR}/Release-iphonesimulator/${FMK_NAME}.framework# -configuration ${CONFIGURATION}# Clean and Building both architectures.xcodebuild -configuration "Release" -target "${FMK_NAME}" -sdk iphoneos -arch armv7 -arch armv7s -arch arm64 clean buildxcodebuild -configuration "Release" -target "${FMK_NAME}" -sdk iphonesimulator -arch x86_64 clean build# Cleaning the oldest.if [ -d "${INSTALL_DIR}" ]thenrm -rf "${INSTALL_DIR}"fimkdir -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/"

然后看图,直接运行,OK

iOS Framework 的制作和特殊情况应用_第11张图片
Paste_Image.png

然后再新建个工程测试一下
欧尼,奔溃了!!!!


iOS Framework 的制作和特殊情况应用_第12张图片
Paste_Image.png

很好解决,这里也添加一下,然后再运行, OK

iOS Framework 的制作和特殊情况应用_第13张图片
Paste_Image.png
iOS Framework 的制作和特殊情况应用_第14张图片
Paste_Image.png

Plcrashreporter 下载地址:

https://www.plcrashreporter.org/download/

你可能感兴趣的:(iOS Framework 的制作和特殊情况应用)