Installation and use of Cocoapods

Source: Internet
Author: User

Cocoapods Configuration 1.先升级Gem (这个步骤可以省略,系统较老需要)
    sudo gem update --system
2.切换cocoapods的数据源
    【先删除,再添加,查看】
    gem sources --remove https://rubygems.org/
    gem sources -a https://ruby.taobao.org/
    gem sources -l
3.安装cocoapods
    sudo gem install cocoapods
    或者(如10.11系统)sudo gem install -n /usr/local/bin cocoapods
4.将Podspec文件托管地址从github切换到国内的oschina
    【先删除,再添加,再更新】
    pod repo remove master
    pod repo add master http://git.oschina.net/akuandev/Specs.git
    pod repo add master https://gitcafe.com/akuandev/Specs.git
    pod repo update
  出现Setting up CocoaPods master repo,说明Cocoapods在将它的信息下载到 ~/.cocoapods里,cd  到该目录里,用du -sh *命令来查看文件大小,每隔几分钟查看一次,我的这个目录最终大小是800M,就是完成了
5.设置pod仓库
    pod setup
6.测试
    【如果有版本号,则说明已经安装成功】
    pod --version
7.利用cocoapods来安装第三方框架
    01 cd 文件路径    进入要安装框架的项目的.xcodeproj同级文件夹 
    02 vim Podfile   在该文件夹中新建一个文件Podfile
    03 在文件中告诉cocoapods需要安装的框架信息
        a.该框架支持的平台
        b.适用的iOS版本
        c.框架的名称
        d.框架的版本
03 Step Open Podfile Press I the insert after input frame information appears below 8. Description then enter ESC:WQ once to exit and save 8.说明   platform :ios, ‘8.0’ 用来设置所有第三方库所支持的iOS最低版本 #use_frameworks!个别需要用到它,比如reactiveCocoa   target ‘MyApp‘ do    pod ‘AFNetworking‘, ‘~> 2.6’   设置框架的名称和版本号 pod ‘ORStackView‘, ‘~> 3.0’    pod ‘SwiftyJSON‘, ‘~> 2.3’  end
platform :ios, ‘8.0‘ 用来设置所有第三方库所支持的iOS最低版本
pod ‘SDWebImage‘,‘~>2.6‘ 设置框架的名称和版本号
版本号的规则:
‘>1.0‘    可以安装任何高于1.0的版本
‘>=1.0‘   可以安装任何高于或等于1.0的版本
‘<1.0‘    任何低于1.0的版本
‘<=1.0‘   任何低于或等于1.0的版本
‘~>0.1‘   任何高于或等于0.1的版本,但是不包含高于1.0的版本
‘~>0‘     任何版本,相当于不指定版本,默认采用最新版本号
9.安装
pod install 第一次初始化(--no-repo-update)
pod update 更新(--no-repo-update)

10.使用pod install命令安装框架后的大致过程:
01 分析依赖:该步骤会分析Podfile,查看不同类库之间的依赖情况。如果有多个类库依赖于同一个类库,但是依赖于不同的版本,那么cocoaPods会自动设置一个兼容的版本。
02 下载依赖:根据分析依赖的结果,下载指定版本的类库到本地项目中。
03 生成Pods项目:创建一个Pods项目专门用来编译和管理第三方框架,CocoaPods会将所需的框架,库等内容添加到项目中,并且进行相应的配置。
04 整合Pods项目:将Pods和项目整合到一个工作空间中,并且设置文件链接。

Cocoapods installation using

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.