1、创建一个framework
2、创建两个类
zwTool1:
#import <Foundation/Foundation.h>
@interface zwTool1 : NSObject
- (void) print;
@end
@implementation zwTool1
- (void) print
{
NSLog(@"%s",__FUNCTION__);
}
@end
zwTool2:
#import <Foundation/Foundation.h>
@interface zwTool2 : NSObject
- (void) myPrint;
@end
#import "zwTool1.h"
@implementation zwTool2
- (void) myPrint
{
zwTool1 *tool = [[zwTool1 alloc]init];
[tool print];
}
@end
3、导入头文件
4、创建一个target,生成一个同时支持模拟器和真机的framework
5、选择 Cross-platform->Aggregate
6、选中target,点击➕新建 run script phase
7、粘贴以下脚本
set -e
set +u
# Avoid recursively calling this script.
if [[ $SF_MASTER_SCRIPT_RUNNING ]]
then
exit 0
fi
set -u
export SF_MASTER_SCRIPT_RUNNING=1
SF_TARGET_NAME=${PROJECT_NAME}
SF_EXECUTABLE_PATH="${SF_TARGET_NAME}.framework/${SF_TARGET_NAME}"
SF_WRAPPER_NAME="${SF_TARGET_NAME}.framework"
if [[ "$SDK_NAME" =~ ([A-Za-z]+) ]]
then
SF_SDK_PLATFORM=${BASH_REMATCH[1]}
else
echo "Could not find platform name from SDK_NAME: $SDK_NAME"
exit 1
fi
if [[ "$SDK_NAME" =~ ([0-9]+.*$) ]]
then
SF_SDK_VERSION=${BASH_REMATCH[1]}
else
echo "Could not find sdk version from SDK_NAME: $SDK_NAME"
exit 1
fi
if [[ "$SF_SDK_PLATFORM" = "iphoneos" ]]
then
SF_OTHER_PLATFORM=iphonesimulator
else
SF_OTHER_PLATFORM=iphoneos
fi
if [[ "$BUILT_PRODUCTS_DIR" =~ (.*)$SF_SDK_PLATFORM$ ]]
then
SF_OTHER_BUILT_PRODUCTS_DIR="${BASH_REMATCH[1]}${SF_OTHER_PLATFORM}"
else
echo "Could not find platform name from build products directory: $BUILT_PRODUCTS_DIR"
exit 1
fi
rm -rf buildProducts
mkdir buildProducts
# Build the other platform.
xcrun xcodebuild -project "${PROJECT_FILE_PATH}" -target "${TARGET_NAME}" -configuration "${CONFIGURATION}" -sdk ${SF_OTHER_PLATFORM}${SF_SDK_VERSION} BUILD_DIR="${BUILD_DIR}" OBJROOT="${OBJROOT}" BUILD_ROOT="${BUILD_ROOT}" SYMROOT="${SYMROOT}" $ACTION
# Smash the two static libraries into one fat binary and store it in the .framework
xcrun lipo -create "${BUILT_PRODUCTS_DIR}/$PRODUCT_NAME.framework/$PRODUCT_NAME" "${SF_OTHER_BUILT_PRODUCTS_DIR}/$PRODUCT_NAME.framework/$PRODUCT_NAME" -output "${PROJECT_DIR}/buildProducts/$PRODUCT_NAME"
cp -rf ${BUILT_PRODUCTS_DIR}/$PRODUCT_NAME.framework ${PROJECT_DIR}/buildProducts
mv ${PROJECT_DIR}/buildProducts/$PRODUCT_NAME ${PROJECT_DIR}/buildProducts/$PRODUCT_NAME.framework
8、选中framework 这是需要暴露的头文件
9、commod +b 编译,选中项目找到静态库的位置
10、将库导入工程
11、导入头文件
#import <frameworktest/frameworktest.h>
zwTool2 *ttol2 = [[zwTool2 alloc]init];
[ttol2 myPrint];
不出意外的话,会有以下崩溃
12、选中工程配置如下
13、调用结果:
2016-12-16 15:47:08.711 zwTool[66386:435568] -[zwTool1 print]