您的位置:首页 > 其它

cocoapos的使用

2016-06-08 18:22 302 查看
查看 cocoapos 当前版本 pod --version
获得 cocoapos 当前路径 which pod

移除现有Ruby默认源  gem
sources --remove https://rubygems.org/
使用新的源
 
gem sources -a https://ruby.taobao.org/
验证新源是否替换成功

gem sources -l

安装CocoaPods

(1)  $sudo gem install cocoapods 备注:苹果系统升级 OS X EL Capitan 后改为 $sudo gem install -n /usr/local/bin cocoapods

(2)  $pod
setup 开始安装


Fetching: fourflusher-0.3.1.gem (100%)

Successfully installed fourflusher-0.3.1

Fetching: claide-1.0.0.gem (100%)

Successfully installed claide-1.0.0

Fetching: xcodeproj-1.1.0.gem (100%)

Successfully installed xcodeproj-1.1.0

Fetching: molinillo-0.4.5.gem (100%)

Successfully installed molinillo-0.4.5

Fetching: cocoapods-try-1.0.0.gem (100%)

Successfully installed cocoapods-try-1.0.0

Fetching: cocoapods-trunk-1.0.0.gem (100%)

Successfully installed cocoapods-trunk-1.0.0

Fetching: cocoapods-stats-1.0.0.gem (100%)

Successfully installed cocoapods-stats-1.0.0

Fetching: cocoapods-search-1.0.0.gem (100%)

Successfully installed cocoapods-search-1.0.0

Fetching: cocoapods-plugins-1.0.0.gem (100%)

Successfully installed cocoapods-plugins-1.0.0

Fetching: cocoapods-downloader-1.0.0.gem (100%)

Successfully installed cocoapods-downloader-1.0.0

Fetching: cocoapods-deintegrate-1.0.0.gem (100%)

Successfully installed cocoapods-deintegrate-1.0.0

Fetching: cocoapods-core-1.0.1.gem (100%)

Successfully installed cocoapods-core-1.0.1

Fetching: cocoapods-1.0.1.gem (100%)

Successfully installed cocoapods-1.0.1

Parsing documentation for fourflusher-0.3.1

Installing ri documentation for fourflusher-0.3.1

Parsing documentation for claide-1.0.0

Installing ri documentation for claide-1.0.0

Parsing documentation for xcodeproj-1.1.0

Installing ri documentation for xcodeproj-1.1.0

Parsing documentation for molinillo-0.4.5

Installing ri documentation for molinillo-0.4.5

Parsing documentation for cocoapods-try-1.0.0

Installing ri documentation for cocoapods-try-1.0.0

Parsing documentation for cocoapods-trunk-1.0.0

Installing ri documentation for cocoapods-trunk-1.0.0

Parsing documentation for cocoapods-stats-1.0.0

Installing ri documentation for cocoapods-stats-1.0.0

Parsing documentation for cocoapods-search-1.0.0

Installing ri documentation for cocoapods-search-1.0.0

Parsing documentation for cocoapods-plugins-1.0.0

Installing ri documentation for cocoapods-plugins-1.0.0

Parsing documentation for cocoapods-downloader-1.0.0

Installing ri documentation for cocoapods-downloader-1.0.0

Parsing documentation for cocoapods-deintegrate-1.0.0

Installing ri documentation for cocoapods-deintegrate-1.0.0

Parsing documentation for cocoapods-core-1.0.1

Installing ri documentation for cocoapods-core-1.0.1

Parsing documentation for cocoapods-1.0.1

Installing ri documentation for cocoapods-1.0.1

13 gems installed

更新gem
sudo gem update --system

 新建工程,并在终端用cd指令到文件夹内

$pod search 第三方






写入以下内容并保存 小提示:(终端vim文件 按 i 可编辑 ,esc 退出编辑,:wq  可保存退出)

platform:ios, '6.0'   

pod 'AFNetworking', '~> 2.3.1'     <-------第三方

8.导入第三方库

$pod install

9.退出终端

以下是我用以前的安装流程安装时出现的一些错误

终端  cocoapods 下载bug调试:

错误1:

Error fetching http://ruby.taobao.org/:
bad response Not Found 404 (http://ruby.taobao.org/specs.4.8.gz)

解决方案:把安装流程中 $gem sources -a http://ruby.taobao.org/   ---改为----> $gem sources -a https://ruby.taobao.org/
错误2:

ERROR:  While executing gem ... (Errno::EPERM)

Operation not permitted - /usr/bin/pod

解决方案:苹果系统升级OS X EL Capitan后会出现的插件错误,将安装流程 4.安装CocoaPods 的 (1)sudo gem install cocoapods ——>改为sudo gem install -n /usr/local/bin cocoapods

错误3:

[!] Unable to satisfy the following requirements:  - `AVOSCloud (~> 3.1.6.3)` required by `Podfile` 

Specs satisfying the `AVOSCloud (~> 3.1.6.3)` dependency were found, but they required a higher minimum deployment target.

解决方案:安装流程:Podfile文件 中   platform:ios, ‘6.0’  后边的 6.0 是平台版本号 ,一定要加上

备注
【链接】CocoaPods的简单使用
http://www.jianshu.com/p/6db4b2a50fca


[b]pod
search Masonry 命令

[/b]

pod
install 命令


 假如我们要使用利用CocoaPods在项目中导入Masonry类库。Masonry类库在GitHub地址是Masonry,要导入类库我们应该测试一下它是否支持CocoaPods,好我们去验证一下。在终端中输入:
pod search Masonry    过几秒钟之后,你会在终端中看到关于Masonry类库的一些信息。如:
第一步:我们要先建好项目,如图:


然后在终端输入:$
cd /Users/liujunjie/Documents/IOS/LJEatAndDrink,如果你不知道自己项目的路径,你可以直接通过拖拽的方式,Mac会给我们加上路径的,哈哈,特快捷。如:



第二步:关闭项目,在终端输入下面的命令:$pod init,你会发现在你的项目中有一个Podfile文件(注意,一定得是这个文件名,而且没有后缀)。

第三步:在终端输入$ open -a Xcode Podfile ,这句话就是使用Xcode打开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 'LJEatAndDrink' do

end

配置 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!

platform :ios, '7.0'

target 'LJEatAndDrink' do

pod 'Masonry'

end

添加这两句文字的意思是,当前Masonry支持的iOS最低版本是iOS 7.0, 要下载最新版本。然后保存关闭。

第四步:在终端输入$ pod install    

等待一会(如果你的网速很慢,可能等待时间长些),完成了,如:

bogon:LJEatAndDrink LJ$ pod install

Updating local specs repositories

CocoaPods 1.0.0.beta.4 is available.

To update use: `gem install cocoapods --pre`

[!] This is a test version we'd love you to try.

For more information see http://blog.cocoapods.org
and the CHANGELOG for this version http://git.io/BaH8pQ.
Analyzing dependencies

Downloading dependencies

Installing Masonry (0.6.4)

Generating Pods project

Integrating client project

[!] Please close any current Xcode sessions and use `LJEatAndDrink.xcworkspace` for this project from now on.

Sending stats

Pod installation complete! There is 1 dependency from the Podfile and 1 total

pod installed.

bogon:LJEatAndDrink LJ$

看这句话:  [!] From now on use `CocoaPodsDemo.xcworkspace`.    它的意思是:以后打开项目就用 LJEatAndDrink.xcworkspace 打开,而不是之前的LJEatAndDrink.xcodeproj文件。你也许会郁闷,为什么会出现LJEatAndDrink.xcodeproj文件呢。这正是你刚刚运行$ pod install命令产生的新文件。除了这个文件,你会发现还多了另外一个文件“Podfile.lock”和一个文件夹“Pods”。
点击 LJEatAndDrink.xcworkspace 打开之后工程之后,项目Xcode目录结构如下图:

总结一下就是:

cd /Users/LJ/Documents/IOS/LJEatAndDrink

 pod init

open -a Xcode Podfile

配置Podfile文件

pod install
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息