cocoapods

来源:互联网 发布:美篇官方软件下载 编辑:程序博客网 时间:2024/06/16 13:42

一,安装
Xcode->homebrew->RVM->Ruby->CocoaPats
安装
1.gem remove https://rubygems.org/
(或者)gem sources -r https://ruby.taobao.org/
2.gem sources -a https://ruby.taobao.org/
3.gem sources -l
4.sudo gem install cocoapods

注:UNIX输入密码的时候他是不会显示出任何字符的

二.使用
1.终端cd进入目录 进入目录的方法:cd+文件路径,此时要注意,cd后面有一个空格,而且路径名称中如果有中文或空格的话需要将有中文或空格的那个部分加上双引号,如:cd /Users/shifeng/”Swift folder”/”SwiftFlickrApp-master 一个极其精美的图片浏览APP”)
2.创建Podfile
yuanwei:HelloAmap1 xalo$ touch Podfile
3.在文件Podfile中输入

如:
source’https://github.com/CocoaPods/Specs.git’
platform:ios,’7.0’#手机的系统
pod’AMap3DMap’#3D地图SDK
pod’AMapSearch’#搜索服务SDK

platform:ios
pod ’SDWebImage’, ‘~> 3.7.3’
pod ’Reachability’, ‘~> 3.0.0’
pod ‘MJRefresh’, ‘~> 3.0.2’

platform :ios, ‘7.0’
pod “AFNetworking”, “~> 2.0”

在引用库时可先进行查询
pod search SDWebImag
查询结果:
CKNetworkImageDownloading implementation for SDWebImage.
pod ‘ComponentKit+SDWebImage’, ‘~> 0.0.2’
- Homepage: https://github.com/eyeem/ComponentKit-SDWebImage
- Source: https://github.com/eyeem/ComponentKit-SDWebImage.git
- Versions: 0.0.2, 0.0.1 [master repo]

CocoaPods项目的源码 在 Github 上管理。该项目开始于 2011 年 8 月 12 日,经过多年发展,现在已经成为 iOS 开发事实上的依赖管理标准工具。开发 iOS 项目不可避免地要使用第三方开源库,CocoaPods 的出现使得我们可以节省设置和更新第三方开源库的时间。

原理

大概研究了一下 CocoaPods 的原理,它是将所有的依赖库都放到另一个名为 Pods 项目中,然后让主项目依赖 Pods 项目,这样,源码管理工作都从主项目移到了 Pods 项目中。发现的一些技术细节有:

Pods 项目最终会编译成一个名为 libPods.a 的文件,主项目只需要依赖这个 .a 文件即可。
对于资源文件,CocoaPods 提供了一个名为 Pods-resources.sh 的 bash 脚本,该脚本在每次项目编译的时候都会执行,将第三方库的各种资源文件复制到目标目录中。
CocoaPods 通过一个名为 Pods.xcconfig 的文件来在编译时设置所有的依赖和参数。

Commands:

+ cache      Manipulate the CocoaPods cache+ init      Generate a Podfile for the current directory.+ install    Install project dependencies to Podfile.lock versions+ ipc        Inter-process communication+ lib        Develop pods+ list      List pods+ outdated  Show outdated project dependencies+ plugins    Show available CocoaPods plugins+ repo      Manage spec-repositories+ search    Search for pods.+ setup      Setup the CocoaPods environment+ spec      Manage pod specs+ trunk      Interact with the CocoaPods API (e.g. publishing new specs)+ try        Try a Pod!+ update    Update outdated project dependencies and create new Podfile.lock
0 0