ios开发开源框架管理工具Cocoapods安装使用

Cocoapod是一个强大的第三方的开源框架的管理工具,其中的各种开源类库,很多都是持续更新;那么我们在使用的时候就可以使用到最新的类库;由于我们在使用开源框架的时候,也难免会遇到 第三方类库可能会出现的Bug,或者由于苹果的SDK更新,各种框架也需要更新,使用Cocoapods的话就可以一键更新到最新的开源框架了!

首先就是要安装Cocoapos了,安装它需要ruby环境,但是较新的Mac 系统已经为我们安装好了ruby,所以我们现在可以直接安装Cocoapods啦!

安装Cocoapods步骤:

1.打开终端,设置root密码

执行如下命令来设置root密码(如果你没有设置root密码的话)

sudo passwd rootNew password:Retype new password:输入密码并且确认即可

2.安装Cocoapods

(1)执行命令:

su输入密码切换到root用户

(2)执行:

gem sources –remove https://rubygems.org/待有反应(输出

https://rubygems.org/ removed from sources

)(3)然后执行:

gem sources -a (输出是

added to sources

)

(4)查看是否关联到镜像,执行

gem sources -l(输出

*** CURRENT SOURCES ***

,代表执行之前的命令是成功的)(5)安装Cocoapods,执行

sudo gem install cocoapods可能需要等待几分钟,Cocoapods库就安装好了,输出如下:

Fetching: i18n-0.7.0.gem (100%)Successfully installed i18n-0.7.0Fetching: thread_safe-0.3.5.gem (100%)Successfully installed thread_safe-0.3.5Fetching: tzinfo-1.2.2.gem (100%)Successfully installed tzinfo-1.2.2Fetching: minitest-5.5.1.gem (100%)Successfully installed minitest-5.5.1Fetching: activesupport-4.2.1.gem (100%)Successfully installed activesupport-4.2.1Fetching: nap-0.8.0.gem (100%)Successfully installed nap-0.8.0Fetching: fuzzy_match-2.0.4.gem (100%)Successfully installed fuzzy_match-2.0.4Fetching: cocoapods-core-0.36.0.gem (100%)Successfully installed cocoapods-core-0.36.0Fetching: claide-0.8.1.gem (100%)Successfully installed claide-0.8.1Fetching: colored-1.2.gem (100%)Successfully installed colored-1.2Fetching: xcodeproj-0.23.0.gem (100%)Successfully installed xcodeproj-0.23.0Fetching: cocoapods-downloader-0.8.1.gem (100%)Successfully installed cocoapods-downloader-0.8.1Fetching: cocoapods-plugins-0.4.1.gem (100%)Successfully installed cocoapods-plugins-0.4.1Fetching: cocoapods-try-0.4.3.gem (100%)Successfully installed cocoapods-try-0.4.3Fetching: netrc-0.7.8.gem (100%)Successfully installed netrc-0.7.8Fetching: cocoapods-trunk-0.6.0.gem (100%)Successfully installed cocoapods-trunk-0.6.0Fetching: molinillo-0.2.1.gem (100%)Successfully installed molinillo-0.2.1Fetching: escape-0.0.4.gem (100%)Successfully installed escape-0.0.4Fetching: open4-1.3.4.gem (100%)Successfully installed open4-1.3.4Fetching: cocoapods-0.36.0.gem (100%)Successfully installed cocoapods-0.36.0Parsing documentation for i18n-0.7.0Installing ri documentation for i18n-0.7.0Parsing documentation for thread_safe-0.3.5Installing ri documentation for thread_safe-0.3.5Parsing documentation for tzinfo-1.2.2Installing ri documentation for tzinfo-1.2.2Parsing documentation for minitest-5.5.1Installing ri documentation for minitest-5.5.1Parsing documentation for activesupport-4.2.1unable to convert "\x84" from ASCII-8BIT to UTF-8 for lib/active_support/values/unicode_tables.dat, skippingInstalling ri documentation for activesupport-4.2.1Parsing documentation for nap-0.8.0Installing ri documentation for nap-0.8.0Parsing documentation for fuzzy_match-2.0.4Installing ri documentation for fuzzy_match-2.0.4Parsing documentation for cocoapods-core-0.36.0Installing ri documentation for cocoapods-core-0.36.0Parsing documentation for claide-0.8.1Installing ri documentation for claide-0.8.1Parsing documentation for colored-1.2Installing ri documentation for colored-1.2Parsing documentation for xcodeproj-0.23.0Installing ri documentation for xcodeproj-0.23.0Parsing documentation for cocoapods-downloader-0.8.1Installing ri documentation for cocoapods-downloader-0.8.1Parsing documentation for cocoapods-plugins-0.4.1Installing ri documentation for cocoapods-plugins-0.4.1Parsing documentation for cocoapods-try-0.4.3Installing ri documentation for cocoapods-try-0.4.3Parsing documentation for netrc-0.7.8Installing ri documentation for netrc-0.7.8Parsing documentation for cocoapods-trunk-0.6.0Installing ri documentation for cocoapods-trunk-0.6.0Parsing documentation for molinillo-0.2.1Installing ri documentation for molinillo-0.2.1Parsing documentation for escape-0.0.4Installing ri documentation for escape-0.0.4Parsing documentation for open4-1.3.4Installing ri documentation for open4-1.3.4Parsing documentation for cocoapods-0.36.0Installing ri documentation for cocoapods-0.36.020 gems installed(6)测试一下pod命令,在终端 执行

exit退出root用户,因为Cocoapods默认不能在root上正常的使用

pod会输出:

sh-3.2# exitexitmacios:~ mac$ podUsage:$ pod COMMANDCocoaPods, the Cocoa library package manager.Commands:+ initGenerate a Podfile for the current directory.+ install Install project dependencies to Podfile.lock versions+ ipcInter-process communication+ libDevelop pods+ listList pods+ outdated Show outdated project dependencies+ plugins Show available CocoaPods plugins+ repoManage spec-repositories+ searchSearches for pods+ setupSetup the CocoaPods environment+ specManage pod specs+ trunkInteract with the CocoaPods API (e.g. publishing new specs)+ tryTry a Pod!+ updateUpdate outdated project dependencies and create newPodfile.lockOptions:–silentShow nothing–version Show the version of the tool–verbose Show more debugging information–no-ansi Show output without ANSI codes–helpShow help banner of specified commandmacios:~ mac$ 输出如上,代码Cocoapods安装成功!

3.使用Cocoapods

首先新建一个ios工程如FirstApp,然后关闭工程[此点很重要,否则会无法正常使用Cocoapods安装类库],切换到工程的根目录(拖拽工程文件夹可以快速的切换)

(1)执行

cd /Users/mac/Desktop/FirstApp(你的工程根目录路径)(2)执行

pod init执行完成之后,会在根目录下创建一个文件:Podfile(3)搜索你需要的类库,只需输入部分字符串即可,自动查找

比如我们来搜索一下AFNetworking类库,执行:

pod search afnet如果是第一次使用Cocoapods搜索的话会满一些,稍等一下,即可看到很多的AF相关的内容出来了,其中有我们想要的AFNetworking框架

部分输出如下:

学做任何事得按部就班,急不得

ios开发开源框架管理工具Cocoapods安装使用

相关文章:

你感兴趣的文章:

标签云: