美文网首页iOS
iOS开发:CocoaPods简单使用介绍

iOS开发:CocoaPods简单使用介绍

作者: Jason_hzb | 来源:发表于2018-05-15 14:32 被阅读10次

    一、摘要

    iOS开发时,项目中会引用许多第三方库,CocoaPods(https://github.com/CocoaPods/CocoaPods)可以用来方便的统一管理这些第三方库。

    二、安装

    下载安装CocoaPods需要Ruby环境

    1、Ruby环境搭建

    gem sources -l #(查看当前ruby的源) 
    gem sources --remove https://rubygems.org/ #(移除当前ruby的源) 
    gem sources -a http://gems.ruby-china.org/ #(设置当前ruby的源为我天朝的) 
    gem sources -l #(再次查看当前ruby的源)
    
    https://rubygems.org/ #默认源
    https://ruby.taobao.org/ #过时的源
    http://gems.ruby-china.org/ #现在的源
    
    *** CURRENT SOURCES ***
    http://gems.ruby-china.org/
    

    2、下载安装CocoaPods

    1.更新gem
    sudo gem update –system
    
    2.安装CocoaPods
    sudo gem install -n /usr/local/bin cocoapods
    pod setup
    
    3.查看CocoaPods安装进度
    cd ~/.cocoapods/
    du -sh
    
    4.搜索第三方库,验证CocoaPods是否成功安装
    pod search mbpro
    
    5.查看CocoaPods版本
    pod --version
    

    三、使用

    1.Podfile官方推荐:
    platform :ios,'8.0'
    
    inhibit_all_warnings!
    source 'https://github.com/CocoaPods/Specs.git'
    
    target '工程名称' do
        pod 'AFNetworking'
    end
    
    2.项目创建CocoaPods
    1、cd ~/desktop/HelloWord(你项目的根目录)
    2、创建Podfile这个文件:
    touch Podfile 回车
    open -e Podfile 出现一个空文件,先不做处理
    3、搜索需要的库:pod search Reachability(你需要的库)会出现对应库的信息
    4、在刚才那空文件中写入需要的保存在终端输入pod install大功告成
    

    四、小技巧

    1.解决cocospods老是卡在Analyzing dependencies~~
    pod install --verbose --no-repo-update
    或者
    pod update --verbose --no-repo-update
    
    2.解决pod setup速度慢

    使用 CocoaPods 的镜像索引。
    一个叫akinliu的朋友在gitcafeoschina上建立了 CocoaPods 索引库的镜像,因为 gitcafe 和 oschina 都是国内的服务器,所以在执行索引更新操作时,会快很多。

    1、pod repo remove master
    2、pod repo add master [https://gitcafe.com/akuandev/Specs.git](https://gitcafe.com/akuandev/Specs.git) 【或者 http://git.oschina.net/akuandev/Specs.git】
    3、git clone https://git.coding.net/CocoaPods/Specs.git ~/.cocoapods/repos/master
    4、pod repo update //更新本地的缓存
    
    如果觉得小编写的对你有帮助,请点击一下文章最下面的喜欢按钮,小编会继续努力哦~

    相关文章

      网友评论

        本文标题:iOS开发:CocoaPods简单使用介绍

        本文链接:https://www.haomeiwen.com/subject/cjxedftx.html