5
28
2014
15

CocoaPods再使用

安装 CocoaPods

CocoaPods 是基于 Ruby 开发的, 其安装需要 Ruby 环境. 幸运的是 MAC 默认都是预装 好 Ruby 的.

在开始安装前, 我们有两点需要准备:

  • 确定 Ruby 环境是好的, 并配置好环境变量PATH.

编辑~/.profile~/.bash_profile , 配置PATH:

export PATH=$HOME/.rvm/bin:$PATH

* 由于 gems 的源被墙了, 需要连 VPN, 或者切换成国内的源:

    $ gem sources --remove https://rubygems.org/
    $ gem sources -a http://ruby.taobao.org/
    # 验证一下
    $ gem sources -l

安装

$ gem install cocoapods
$ gem which cocoapods
/Users/nuoerlz/.rvm/gems/ruby-1.9.3-p194/gems/cocoapods-0.29.0/lib/cocoapods.rb
$ type -all pod
pod is /Users/nuoerlz/.rvm/gems/ruby-1.9.3-p194/bin/pod

升级

升级只需要重新安装一遍:

$ gem install cocoapods

另, 也可以安装预发布版:

$ gem install cocoapods --pre

使用 CocoaPods

在单一Target的项目中使用 CocoaPods

一般情况下, 我们都是想在现有的工程中加入使用 CocoaPods, 这种工程只有一个 Target, 且没有用到Workspace. 对于这种情况, 使用 CocoaPods 还是很简单的, 网 上的很多教程也大多数是这种情况, 可以直接参考:

场景1:利用CocoaPods,在项目中导入AFNetworking类库
Adding Pods to an Xcode project

另一种常见情况是, 在新的工程里使用 CocoaPods, 这种工程也是只有一个Target, 且 没有使用Workspace, 这和上面提到的是很类似的, 直接参考就行, 还可以参考:

Creating a new Xcode project with CocoaPods

在有多个Target多个工程且已有Workspace的项目中使用 CocoaPods

一般情况, 有多个工程的Workspace的目录结构:

nzplayer_dir_list

截图中的Workspace包含了两个工程(xcodeproj), 其中, NZPlayerKit是静态库工程, 其 目标是编译出 libNZPlayerKit.a, 而NZPlayer是普通的App工程, 最终会生成 NZPlayer.app, 其是依赖 libNZPlayerKit.a :

nzplayer_project

nzplayer_libs_ref

OK, 现在我们想在 NZPlayerKit.xcodeproj 和 NZPlayer.xcodeproj 中使用第三方的开 源库, 并用 CocoaPods 管理, 看了一下 CocoaPods官网的文档, 跟本没有说明 如何配置多工程的! 好么! 只能试啊试...

假设 NZPlayerKit.xcodeproj 中的 NZPlayerKit(Target) 需要用到的第三方库是:

UMeng

NZPlayer.xcodeproj 中的 NZPlayer(Target) 需要用到的第三方库是:

UMeng
pod AFNetworking
pod RSTWebViewController

在这里, 选择这几个库的原因是, 它们开放的方式是各不一样的, 这样才更具普遍性. 其中, UMeng 是不开源的, 它提供了静态库(lib*.a); AFNetworking 是典型的Pod; RSTWebViewController 是还在开发中的, 还没发布任何版本, 只能直接引用其git repo.

那么, 可以这么配置Podfile(Podfile语法):

inhibit_all_warnings!

# 使用现有的 workspace(NZ.xcworkspace), 不要生成新的!
workspace 'NZ.xcworkspace'
# 配置默认 xcodeproj, 路径是相对于 Podfile 的路径. 这是必须的, 否则会报Syntax错误.
xcodeproj 'NZPlayerKit/NZPlayerKit.xcodeproj'

## 下面就是配置各个Target了! 也就是说, CocoaPods 面向的主配置对象是Target而不
## 是Project. 当然你得指定该Target属于那个Project, 否则会使用前面配置默认的.

# 配置NZPlayerKit(Target)
target :NZPlayerKit do
    # 该Target属于的工程
    xcodeproj 'NZPlayerKit/NZPlayerKit.xcodeproj'
    # 平台和系统版本
    platform :ios, "5.0"
    # UMeng pod
    pod 'UMeng', '2.2.1'
end

# 配置NZPlayer(Target)
target :NZPlayer do
    xcodeproj 'NZPlayer/NZPlayer.xcodeproj'
    platform :ios, "7.0"
    pod 'UMeng', '2.2.1'
    pod "AFNetworking", "~> 2.0"
    pod 'RSTWebViewController', :git => 'https://github.com/rileytestut/RSTWebViewController.git'
end

OK, 保存Podfile, 执行pod install:

[nuoerlz NZPlayer-Workpace]$ pod install
Analyzing dependencies
Pre-downloading: `RSTWebViewController` from `https://github.com/rileytestut/RSTWebViewController.git`
Downloading dependencies
Installing AFNetworking (2.2.1)
Installing NJKWebViewProgress (0.1.8)
Installing RSTWebViewController (0.1)
Installing UMeng (2.2.1)
Generating Pods project
Integrating client projects

最后, 工程们长这样:

nzplayerkit_pods

NZPlayerKit 对 libPods-*.a 的依赖关系是这么的:

nzplayerkit_libs_ref

NZPlayer 对 libPods-*.a 的依赖关系是这么的:

nzplayer_libs_ref_2

看了这些截图, CocoaPods 的原理也就不日明了....

Reference

Getting Started
Podfile Syntax Reference
CocoaPods安装和使用教程

(end)

Category: iOS | Tags: Tools Xcode iOS objc Pods | Read Count: 5752
essayhelpers review 说:
2019年3月25日 03:47

CocoaPods is grounded on Ruby and needs a Ruby environment for the sake of installation. Luckily, MAC is pre-installed with Ruby by evasion. We met to essayhelpers review a few years ago. Before we look forward to the installation, we have two things to remember: Don’t forget that the Ruby environment is fine, and arrange the atmosphere adjustable PATH.

status video 说:
2019年4月28日 20:28

download whatsapp status love status and show your love to your partner how much you love them.

gbc 说:
2019年5月05日 23:58

Our academic pursuits, along with a range of extracurricular activities, help in honing a child's skills and ensuring that he/shegrows to be a mature and responsible citizen.
top public school in greater noida
admission 2019 best school in greater noida
premium school in noida

golf clash hacks 说:
2019年5月27日 00:52

Trophies are the necessary elements to get more crates in the game. You can get trophies by participating in a tournament.

fgg 说:
2019年5月31日 00:36

Apple products are revered for its quality, precision and great design. SRSG started its operations as Apple technology partners in the year 1997.

apple reseller in Kolkata

Broadcast consultants in india

apple authorized service center in delhi

system integration service providers

ipad service center in kolkata

webnovel 说:
2019年6月09日 16:24

The information you have posted is very useful. The sites you have referred was good. Thanks for sharing

<a href="http://www. 说:
2019年9月02日 19:21

<a href="http://www.sus.edu.in">Best Engineering College in North India</a>
Nice and informative.

abc 说:
2019年11月07日 23:18

Provides multiple learning environment of International standard with holistic system of education at an affordable cost for the successful life of young generation.
best paramedical college north india.
agriculture college in dehradun
The goal of the society is to create professionally well skilled students To achieve the said goal, arrangements have been made with the pioneers and front runners both in India and abroad.
best cbse school in dehradun

abc 说:
2019年11月07日 23:18

Our approach brings together best-in-class virtualized compute, storage, and networking infrastructure.
IT services & support company in uae
email security partner in uae
AWS partner in uae
cloud partner in uae

AP 10th Maths Questi 说:
2022年9月10日 22:03

Mathematics is one of the tough subjects and also an easy subject for class 10th standard students of TM, EM, AP 10th Maths Question Paper UM and HM studying at government and private schools of the state. Department of School Education and teaching staff of various institutions have designed and suggested the Mathematics question paper with solutions for all chapters topic wide for each lesson of the course, and the AP SSC Maths Model Paper 2023 Pdf designed based on the new revised syllabus and curriculum.

gloria08 说:
2023年3月14日 22:36

IG downloader Support for downloading videos from Instagram on desktop or mobile it download videos very fast it and is an easy and valuable tool for saving images from Instagram posts. IG downloader can download a number of pictures at once ,and its So easy to manage .the tool can download videos from multiple Instagram accounts simultaneously to get more information <a href="https://rosalind.info/users/IG-downloader/">download instagram photos</a>

Rrogers 说:
2023年4月10日 00:22

A MIC is generally regarded as the most basic laboratory measurement of the activity of an antimicrobial agent against an organism. Because a lower MIC value indicates that less of the drug is required to inhibit the growth of the organism, drugs with lower MIC scores are more effective antimicrobial agents. Currently, there are a few web-based, freely accessible MIC databases. Get more information [url=https://sites.google.com/view/mictestco/home]mic test for android[/url]

<a href="://sites.go 说:
2023年4月10日 00:35

To determine MIC by dilution methods, antibiotics are also needed in a substance that requires preliminary dissolution to obtain a stock solution and then dilution to obtain an appropriate starting concentration. For most antibiotics, water is both a solvent and a diluter, including for most beta-lactams, fluoroquinolones, and aminoglycosides. Some require alcohol as a solvent, especially macrolides, chloramphenicol, and rifampicin, while others require a phosphate buffer or dimethyl sulfoxide DMSO.

things to do 说:
2023年5月11日 20:44

Have you ever had a boring weekend and want to have fun but out of ideas? Have you ever been to a new city and want to discover it but don't know where to start? Let me introduce to you, things to do near me.


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter

Host by is-Programmer.com | Power by Chito 1.3.3 beta | Theme: Aeros 2.0 by TheBuckmaker.com