我在公司的廢棄項(xiàng)目上做改造。點(diǎn)擊查看項(xiàng)目送挑。
創(chuàng)建podfile
終端cd到工程根目錄绑莺,執(zhí)行命令:
pod init
然后用open命令打開(kāi)podfile文件:
open podfile
以下是默認(rèn)生成的文件內(nèi)容:
# Uncomment the next line to define a global platform for your project
# platform :ios, '9.0'
target 'Syiar' do
# Comment the next line if you don't want to use dynamic frameworks
use_frameworks!
# Pods for Syiar
target 'SyiarTests' do
inherit! :search_paths
# Pods for testing
end
target 'SyiarUITests' do
# Pods for testing
end
end
導(dǎo)入AFNetworking
先單獨(dú)嘗試集成AFNetworking
修改podfile,添加下面一行:
# Pods for Syiar
pod 'AFNetworking', '~> 3.0'
然后回到終端惕耕,執(zhí)行安裝命令:
pod install
成功后會(huì)生成xcworkspace文件:
[!] Please close any current Xcode sessions and use `Syiar.xcworkspace` for this project from now on.
Pod installation complete! There is 1 dependency from the Podfile and 1 total pod installed.
有時(shí)候也會(huì)伴隨一些警告纺裁。我碰到三條警告:
[!] Automatically assigning platform `iOS` with version `9.0` on target `Syiar` because no platform was specified. Please specify a platform for this target in your Podfile. See `https://guides.cocoapods.org/syntax/podfile.html#platform`.
[!] The `Syiar [Debug]` target overrides the `OTHER_LDFLAGS` build setting defined in `Pods/Target Support Files/Pods-Syiar/Pods-Syiar.debug.xcconfig'. This can lead to problems with the CocoaPods installation
- Use the `$(inherited)` flag, or
- Remove the build settings from the target.
[!] The `Syiar [Release]` target overrides the `OTHER_LDFLAGS` build setting defined in `Pods/Target Support Files/Pods-Syiar/Pods-Syiar.release.xcconfig'. This can lead to problems with the CocoaPods installation
- Use the `$(inherited)` flag, or
- Remove the build settings from the target.
第一條是提醒我們指定platform。打開(kāi)podfile司澎,發(fā)現(xiàn)已經(jīng)默認(rèn)添加了欺缘,但是需要取消注釋:
platform :ios, '9.0'
后面兩條需要我們打開(kāi)新生成的xcworkspace - 如果之前打開(kāi)了工程要先關(guān)閉。
然后在Build Settings找到other linker flags挤安,將里面原有的刪除谚殊,添加$(inherited)。Xcode會(huì)自動(dòng)展開(kāi)成需要的蛤铜。
會(huì)到終端嫩絮,再執(zhí)行一次pod install。警告消失了围肥。
然后在Xcode中刪除之前Carthage導(dǎo)入的framework剿干。再在Build Phases 下查找有無(wú) 包含以下內(nèi)容的 Run Script:
/usr/local/bin/carthage copy-frameworks
如果有,刪除Input Files中的AFNetworking:
$(SRCROOT)/Carthage/Build/iOS/AFNetworking.framework
Xcode編譯穆刻,成功置尔。
導(dǎo)入其他庫(kù)
在podfile中添加其他需要導(dǎo)入的庫(kù)嘶摊。我添加了下面這些:
pod 'YYModel'
pod 'Masonry'
pod 'SDWebImage'
pod 'MBProgressHUD'
pod 'SSZipArchive'
然后回到終端邑跪,執(zhí)行安裝命令:
pod install
完成后回到Xcode刪除對(duì)應(yīng)的framework。
整個(gè)刪除前文提到Run Script腳本导饲。去到工程目錄朵锣,刪掉Carfile谬盐、Carfile.resolved、Carthage/文件夾猪勇。
ZipArchive這個(gè)庫(kù)的引入方式需要修改一下:
#import <SSZipArchive/ZipArchive.h>
最后將Pods/文件夾加入到.gitingore中:
# CocoaPods
#
# We recommend against adding the Pods directory to your .gitignore. However
# you should judge for yourself, the pros and cons are mentioned at:
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
#
Pods/
完成设褐。