一、新建一個工程,左邊選擇iOS-Framework & Library 而後選擇Cocoa Touch Framework。 xcode
二、如今能夠建立所須要封裝的類和方法。 架構
三、選中工程target裏面的Build Phases,而後選擇Build Phases下的 Headers選項,若沒有該選項,則可經過Xcode的Editor-Add Build Phase-Add Headers Build Phase添加(若該項不能選擇,請先點擊Build Phases下面的空白處,激活該選項)。 iphone
四、把須要對外開放的.h文件從Headers的Project裏面拖到Public裏面。 測試
五、新工程裏面會有一個與工程同名的.h文件,須要在這個文件裏面導入對外開放的.h文件(#imporf<工程名/xxx.h>)。 ui
六、選擇target裏面的Build Settings,在Architectures裏面添加Framework支持的架構,默認支持armv七、arm64,如今須要增長armv7s。 code
七、選擇模擬器裏面的Generic iOS Device ,記得先clean一下在run。 ip
八、點開Xcode左邊導航欄的Products,如今能夠看到裏面的Framework由紅色變成了黑色,選中它而後show in Finder, 把它copy到桌面。 get
九、打開終端,咱們來測試一下新建的Framework支持哪些架構。it
cd Desktop lipo -info FFrameworkT.framework/FFrameworkT Architectures in the fat file: FFrameworkT.framework/FFrameworkT are: armv7 armv7s arm64
十、如今新建一個single view 工程,選中target裏面的General-Embeded Binaries,點擊裏面的+號,選擇 Add oother... ,找到桌面的新建的Framework,而後照常使用。 io
十一、選擇任意一個模擬器,run,這時出現了以下錯誤:
ld: warning: ignoring file /Users/AZmake/Desktop/testFFFF/FFrameworkT.framework/FFrameworkT, file was built for armv7 which is not the architecture being linked (x86_64): /Users/AZmake/Desktop/testFFFF/FFrameworkT.framework/FFrameworkT
Undefined symbols for architecture x86_64:
"_FFrameworkTVersionNumber", referenced from:
-[ViewController viewDidLoad] in ViewController.o"_FFrameworkTVersionString", referenced from:
-[ViewController viewDidLoad] in ViewController.o"_OBJC_CLASS_$_love", referenced from:
objc-class-ref in ViewController.old: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
這是什麼緣由??????
由於新建的Framework不支持模擬器的x86_64架構,如今這個Framework只能在真機上運行。
我想要在模擬器上運行,怎麼辦??????
一、選中Framework的target,經過Xcode的Editor-Add target... , 而後選擇最下面的Other - Aggregate,如何Framework的名字。
二、選中新添加的target(有個靶同樣的圖標),Build Phases,點擊+號添加 Run Script,雙擊改行把名字 Run Script 改成工程的名字。
三、在腳本編輯區域寫入以下命令:
# Sets the target folders and the final framework product. 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,選擇模擬器裏面的Generic iOS Device ,記得先 clean 一下在run。若沒有錯誤,完成後會有Finder彈窗出現,如今一個同時支持模擬器和真機的
Framework就完成了。咱們能夠在項目的Products裏面找到Framework。
五、把Framework複製到桌面看看它支持哪些架構。
cd Desktop/ lipo -info AZFrameworks.framework/AZFrameworks Architectures in the fat file: AZFrameworks.framework/AZFrameworks are: i386 x86_64 armv7 armv7s arm64
如今能夠看到Framework支持i386 x86_64 armv7 armv7s arm64 這些架構。