• iOS pods集成与使用介绍


    CocoaPods简介

    在进行iOS开发的时候,总免不了使用第三方的开源库,比如SBJson、AFNetworking、Reachability等等。使用这些库的时候通常需要:

    下载开源库的源代码并引入工程
    向工程中添加开源库使用到的framework
    解决开源库和开源库以及开源库和工程之间的依赖关系、检查重复添加的framework等问题
    如果开源库有更新的时候,还需要将工程中使用的开源库删除,重新执行前面的三个步骤,顿时头都大了。。。

    自从有了CocoaPods以后,这些繁杂的工作就不再需要我们亲力亲为了,只需要我们做好少量的配置工作,CocoaPods会为我们做好一切!

    CocoaPods是一个用来帮助我们管理第三方依赖库的工具。它可以解决库与库之间的依赖关系,下载库的源代码,同时通过创建一个Xcode的workspace来将这些第三方库和我们的工程连接起来,供我们开发使用。
    使用CocoaPods的目的是让我们能自动化的、集中的、直观的管理第三方开源库。

    (Mac ox 10.11+)    CocoaPods安装,卸载,使用说明

    一、全新安装前,先检查是否有安装残留

    由于Mac 10.11更改了安全机制,所以cocoapods得安装和卸载命令也有所改变,

    1、如果之前装过cocopods,最好先卸载掉,卸载命令:

    $ sudo gem uninstall cocoapods【Mac 10.10之前】

    $ sudo gem uninstall -n /usr/local/bin cocoapods【Mac 10.11之后】

    2、先查看本地安装过的cocopods相关东西【本步骤没有必要】,命令如下:

    $ gem list --local | grep cocoapods

    会显示如下:

    cocoapods-core (0.39.0)

    cocoapods-downloader (0.9.3)

    cocoapods-plugins (0.4.2)

    cocoapods-search (0.1.0)

    cocoapods-stats (0.6.2)

    cocoapods-trunk (0.6.4)

    cocoapods-try (0.5.1)

    然后逐个删除吧:

    $ sudo gem uninstall cocoapods-core【Mac 10.10之前】

    $ sudo gem uninstall -n /usr/local/bin cocoapods-core【Mac 10.11之后】

    。。。
    二。安装
    要使用CocoaPods 那就要下载安装它,而下载安装CocoaPods需要Ruby环境
    1.准备工作
    Mac os 本身自带Ruby,但还是更新一下保险,因为我第一次安装在没有更新Ruby的情况下就失败了。

    a) 查看下当前ruby版本:打开终端输入 ruby -v(确实安装了,不过用这个版本接下来工作失败了,所以更新下ruby)(更新方法自己百度。。。)

    1. chendeMacBook-Air:~ chen$ ruby -v  
    2. ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-darwin15]  
    3. chendeMacBook-Air:~ chen$  
    1. chendeMacBook-Air:~ chen$ ruby -v  
    2. ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-darwin15]  
    3. chendeMacBook-Air:~ chen$  

    b)cocoapods镜像:https://gems.ruby-china.org/   好像现在不支持淘宝了

    终端输入如下命令(把Ruby镜像指向Ruby China,避免被墙,你懂得)

    $gem sources --remove https://rubygems.org/ 
    $gem sources --add https://gems.ruby-china.org/
    $gem sources -l  (用来检查使用替换镜像位置成功)

    1. chendeMacBook-Air:~ chen$ gem sources -l  
    2. *** CURRENT SOURCES ***  
    3. https://gems.ruby-china.org/  
    1. chendeMacBook-Air:~ chen$ gem sources -l  
    2. *** CURRENT SOURCES ***   
    3. https:2.下载安装cocoapods 

    (2)升级gem,在终端输入命令

    $ sudo gem update --system

    接着会要求输入电脑密码,输入密码后回车,就开始升级了。如果看到下面这句话,说明升级成功了。

    RubyGems system software updated

    还有一点需要注意,pod setup在执行时,会输出Setting up CocoaPods master repo,但是会等待比较久的时间。这步其实是 Cocoapods 在将它的信息下载到 ~/.cocoapods目录下,如果你等太久,可以试着 cd 到那个目录,用du -sh *来查看下载进度。你也可以参考本文接下来的使用 cocoapods 的镜像索引一节的内容来提高下

    载速度。

    安装过程遇到的问题:

    1、Ruby版本过低(更新就行了)

    2、

    1. $ pod setup  
    2. Setting up CocoaPods master repo  
    3. [!] /usr/bin/git clone https://github.com/CocoaPods/Specs.git master  
    4. Cloning into ‘master’…  
    5. error: RPC failed; curl 56 SSLRead() return error -36  
    6. fatal: The remote end hung up unexpectedly  
    7. fatal: early EOF  
    8. fatal: index-pack failed   
    1. $ pod setup  
    2. Setting up CocoaPods master repo  
    3. [!] /usr/bin/git clone https://github.com/CocoaPods/Specs.git master  
    4. Cloning into ‘master’…  
    5. error: RPC failed; curl 56 SSLRead() return error -36  
    6. fatal: The remote end hung up unexpectedly  
    7. fatal: early EOF  
    8. fatal: index-pack failed   

     

    3、

    1. $ pod setup  
    2. Setting up CocoaPods master repo  
    3. [!] /usr/bin/git clone https://github.com/CocoaPods/Specs.git master  
    4. Cloning into ‘master’…  
    5. error: RPC failed; curl 56 SSLRead() return error -9806  
    6. fatal: The remote end hung up unexpectedly  
    7. fatal: early EOF  
    8. fatal: index-pack failed  
    1. $ pod setup  
    2. Setting up CocoaPods master repo  
    3. [!] /usr/bin/git clone https://github.com/CocoaPods/Specs.git master  
    4. Cloning into ‘master’…  
    5. error: RPC failed; curl 56 SSLRead() return error -9806  
    6. fatal: The remote end hung up unexpectedly  
    7. fatal: early EOF  
    8. fatal: index-pack failed  

     

    4、

    1. $ pod setup  
    2. Setting up CocoaPods master repo  
    3. [!] /usr/bin/git clone https://github.com/CocoaPods/Specs.git master  
    4. Cloning into ‘master’…  
    5. error: RPC failed; curl 18 transfer closed with outstanding read data remaining  
    6. fatal: The remote end hung up unexpectedly  
    7. fatal: early EOF  
    8. fatal: index-pack failed  
    1. $ pod setup  
    2. Setting up CocoaPods master repo  
    3. [!] /usr/bin/git clone https://github.com/CocoaPods/Specs.git master  
    4. Cloning into ‘master’…  
    5. error: RPC failed; curl 18 transfer closed with outstanding read data remaining  
    6. fatal: The remote end hung up unexpectedly  
    7. fatal: early EOF  
    8. fatal: index-pack failed  

     

    解决方法:上面错误主要是os10.11+和cocoapods1.0+版本升级的安全机制更改造成的。主要出现在pod setup过程中。且该过程等待时间非常长,所以,你可以在$sudo gem install -n /usr/local/bin cocoapods命令后直接执行$Git clone https://git.coding.net/CocoaPods/Specs.git ~/.cocoapods/repos/master 该过程作用与 pod setup作用相同,作者亲测。效果极佳!!!!

    可能出的错

    1.

    解决办法

    sudo xcode-select -switch /Applications/Xcode-beta.app/Contents/Developer

    后面的地址你可以打开Xcode显示包内容,找到那个文件夹拖到终端里面比较不容易错。

     2.

    官网是这样给推荐的: 
    在创建Podfile的时候,用这种格式使用,

    3.

    解决办法:不要使用文本编辑去编辑Podfile,使用Xcode编辑,或者使用终端敲命令去编辑。或者输入格式错误,没输入运行版本:$platform:ios, ‘9.0‘

    三:使用CocoaPods

    终端中 cd到项目路径

    建立Podfile(配置文件)

    $vim Podfile

    键盘输入 i 进入编辑模式,输入

    platform :ios, '7.0' 

    pod 'MBProgressHUD', '~> 0.8’ (之前的,我的电脑上已经无效了,报错: [!] The dependency `MBProgressHUD (~> 0.8)` is not used in any concrete target.)

    (现在使用:MyApp 替换成自己的项目名)

    target 'MyApp' do

    pod 'AFNetworking', '~> 2.6'

    pod 'ORStackView', '~> 3.0'

    end

    然后按Esc,并且输入“ :”号进入vim命令模式,然后在冒号后边输入wq

    再输入  $pod install

    为了确定AFNetworking是否支持CocoaPods,可以用CocoaPods的搜索功能验证一下。在终端中输入:

    $ pod search AFNetworking

    2)出现如下警告

    [!] Your Podfile has had smart quotessanitised. To avoid issues in the future, you should not use TextEdit forediting it. If you are not using TextEdit, you should turn off smart quotes inyour editor of choice.

    解决办法:不要使用文本编辑去编辑Podfile,使用Xcode编辑,或者使用终端敲命令去编辑。

    (3) 执行pod install 或pod update 命令后,updating local specsrepositories 卡住不动

    解决办法:pod install 被墙了,换成新的命令pod install --verbose --no-repo-update

    (4) 项目运行时报错:Thefile “Pods.xcconfig” couldn’t be opened because there is no such file.

    解决办法:pod update就可以了。

    关于 Podfile.lock

    当你执行pod install之后,除了 Podfile 外,CocoaPods 还会生成一个名为Podfile.lock的文件,Podfile.lock 应该加入到版本控制里面,不应该把这个文件加入到.gitignore中。因为Podfile.lock会锁定当前各依赖库的版本,之后如果多次执行pod install 不会更改版本,要pod update才会改Podfile.lock了。这样多人协作的时候,可以防止第三方库升级时造成大家各自的第三方库版本不一致。

    看过其他教程的人一定会奇怪,很多教程中用的是pod update 命令,为什么你一直在提pod install,因为pod update会更新的你Podfile.lock文件到最新版本,接下来的害处就如上段所说。

    所以千万记住,无论是自己的项目,还是跑别人的源码,一定要用pod install,至于pod update,看你自己是不是要三方升级类库(我还是建议最好在Podfile中指定版本,想要升级,只需更改Podfile中的版本号,再pod install)。

    11、pod update
    若果Podfile中指定的依赖库版本不是写死的,当对应的依赖库有了更新,无论有没有Podfile.lock文件都会去获取Podfile文件描述的允许获取到的最新依赖库版本。

    1. pod 'AFNetworking'      //不显式指定依赖库版本,表示每次都获取最新版本  (<span style="color: rgb(50, 62, 50); font-family: Arial; font-size: 14px; line-height: 26px;">11、</span><span style="color: rgb(50, 62, 50); font-family: Arial; font-size: 14px; line-height: 26px;">pod update</span>)  
    2. pod 'AFNetworking', '2.0'     //只使用2.0版本    
    3. pod 'AFNetworking', '> 2.0'     //使用高于2.0的版本    
    4. pod 'AFNetworking', '>= 2.0'     //使用大于或等于2.0的版本    
    5. pod 'AFNetworking', '< 2.0'     //使用小于2.0的版本    
    6. pod 'AFNetworking', '<= 2.0'     //使用小于或等于2.0的版本    
    7. pod 'AFNetworking', '~> 0.1.2'     //使用大于等于0.1.2但小于0.2的版本    
    8. pod 'AFNetworking', '~>0.1'     //使用大于等于0.1但小于1.0的版本    
    9. pod 'AFNetworking', '~>0'     //使用最新版本,与不显示指定依赖库版本相同 
     
  • 相关阅读:
    Trajectory Estimation for Geo-Fencing Applications on Small-Size Fixed-Wing UAVs
    A RUGD Dataset for Autonomous Navigation and Visual Perception in Unstructured Outdoor Environments
    DISCOMAN: Dataset of Indoor SCenes for Odometry, Mapping and Navigation
    On Data Sharing Strategy for Decentralized Collaborative Visual-Inertial Simultaneous Localization and Mapping
    Robust High Accuracy Visual-Inertial-Laser SLAM System
    On Data Sharing Strategy for Decentralized Collaborative Visual-Inertial Simultaneous Localization and Mapping
    FLAME: Feature-Likelihood Based Mapping and Localization for Autonomous Vehicles
    Visual-Based Autonomous Driving Deployment from a Stochastic and Uncertainty-Aware Perspective
    Data Flow ORB-SLAM for Real-Time Performance on Embedded GPU Boards
    maven安装本地jar
  • 原文地址:https://www.cnblogs.com/yecong/p/6016461.html
Copyright © 2020-2023  润新知