使用Cocapods管理开源库

1.初始化pod,进入到项目的目录下执行

pod init

执行完成之后会出现Podfile文件
2.编辑Podfile文件

# Uncomment this line to define a global platform for your project
# platform :ios, '8.0'
# Uncomment this line if you're using Swift
# use_frameworks!

target 'MagicBox' do
platform:ios,'7.0'#所有库支持的ios最低版本
pod 'AFNetworking','~>2.3.1'#开源库版本号
pod 'SVProgressHUD','~>1.0'
pod 'Cordova','~>3.5.0'
pod 'GCJSONKit','~>1.5.0'
pod 'CordovaPlugin-console','~>0.2.10'
pod 'CordovaPlugin-device','~>0.2.11'
pod 'CordovaPlugin-network-information','~>0.2.3'
end

target 'MagicBoxTests' do

end

target 'MagicBoxUITests' do

end

3.安装开源库

pod install

执行成功之后会显示

Updating local specs repositories
Analyzing dependencies
Downloading dependencies
Installing AFNetworking (2.3.1)
Installing Cordova (3.5.0)
Installing CordovaPlugin-console (0.2.10)
Installing CordovaPlugin-device (0.2.11)
Installing CordovaPlugin-network-information (0.2.3)
Installing GCJSONKit (1.5.0)
Installing SVProgressHUD (1.1.3)
Generating Pods project
Integrating client project

[!] Please close any current Xcode sessions and use `DemoApp.xcworkspace` for this project from now on.
Sending stats
Pod installation complete! There are 7 dependencies from the Podfile and 7 total pods installed.

4.打开创建的DemoApp.xcworkspace,在桥接文件里面加入引入库文件的代码即可

#import "JSONKit.h"
#import "SVProgressHUD.h"
#import "CDV.h"
#import "AFNetworking.h"
#import "CDVLogger.h"
#import "CDVDevice.h"
#import "CDVConnection.h"

标签: swift

添加新评论