我们在 Objective c 中创建了 Framework,它的工作非常完美。
按照以下简单步骤创建框架
1) 创建新框架,
在xcode中选择
file =>New =>Project =>cocoatouchframework =>Next =>GiveframeworkName =>Create
2) 在项目中添加.h 和.m 文件,用于创建Framework。
3) 在构建阶段在 Public Headers 中添加文件,该文件将显示在您的框架中。
4) 点击项目名称DemoFramework然后选择+按钮然后
选择
Cross-platform =>Aggregate
5) 添加运行脚本
6) 在运行脚本中添加以下代码到 Aggregate(marge)iPhone 和模拟器框架。
# ============Script Start==============
if [ "${ACTION}" = "build" ]
then
# Set the target folders and the final framework product.
INSTALL_DIR=${SYMROOT}/DemoFramework.framework
DEVICE_DIR=${SYMROOT}/Debug-iphoneos
SIMULATOR_DIR=${SYMROOT}/Debug-iphonesimulator
# Create and renews the final product folder.
mkdir -p "${INSTALL_DIR}"
rm -rf "${INSTALL_DIR}"
rm -rf "${INSTALL_DIR}/DemoFramework"
# Copy the header files to the final product folder.
ditto "${DEVICE_DIR}/DemoFramework.framework/Headers"
"${INSTALL_DIR}/Headers"
# Copy the info.plist file to the final product folder
ditto "${DEVICE_DIR}/DemoFramework.framework/info.plist"
"${INSTALL_DIR}"
# Copy the ResoureBundle.bundle file to the final product folder
ditto "${DEVICE_DIR}/DemoFramework.framework/ResourceBundle.bundle"
"${INSTALL_DIR}/ResourceBundle.bundle"
# Use the Lipo Tool to merge both binary files (i386 + armv6/armv7)
into one Universal final product.
lipo -create "${DEVICE_DIR}/DemoFramework.framework/DemoFramework"
"${SIMULATOR_DIR}/DemoFramework.framework/DemoFramework" -output
"${INSTALL_DIR}/DemoFramework"
fi
# ============Script End==============
7) 现在分三步构建项目
1) 为 iPhone 设备构建。
您将看到为 iPhone 设备创建了框架,并且框架位置显示在项目的派生数据中,如下所示。
2) 为模拟器构建。
您将看到为模拟器创建了框架,并且框架位置显示在项目的派生数据中,如下所示。
3) 这是创建框架的最后一步,
在构建选项中选择聚合并构建应用程序,请参见下面的屏幕截图。
最后你的框架被创建在任何应用程序中使用这个框架,框架位置在下面的派生数据中。
希望这个简单的步骤可以帮助某人在目标 C 中创建框架。