xcond7.1不能用ios cocoapods使用的吗

Got 5-minutes? We'd love you to share some of your thoughts regarding Envato.
AdvertisementCodeAdvertisementCocoaPods is an easy-to-use dependency management tool for iOS and OS X development. Even though CocoaPods is fairly clear and simple to use, I feel that many cocoa developers are reluctant to give it a try. In this tutorial, I will show you how to get started with CocoaPods in less than five minutes.
What Is CocoaPods?
CocoaPods is a dependency management tool for iOS and OS X development. It makes managing third party libraries in an Xcode project easy and straightforward. CocoaPods has gained considerable traction in the cocoa community, and as a result, hundreds of open source libraries now provide support for CocoaPods. To get an idea of which libraries are available through CocoaPods, visit the
website and search for some of your favorite third party libraries. Companies like TestFlight, Mixpanel, and Google make their libraries available through CocoaPods.
Why Should I Use CocoaPods?
Working with third party libraries in an Xcode project isn't always easy and it can often be a pain, especially when integrating non-ARC libraries in an ARC-enabled project.
started the CocoaPods project to ease this pain. Before switching to CocoaPods, I did wha they manually copy the source files of third party libraries into an Xcode project and compile those files with the rest of the project. Even though this method worked fine, updating a project's dependencies was a cumbersome and error-prone process.
CocoaPods makes managing a project's dependencies much easier and intuitive. You only need to specify which dependencies, or pods, you want to include in your project and CocoaPods takes care of the rest. Updating a pod to a new version is as simple as executing a single command on the command line. If you have avoided the command line in the past, now might be a good time to become familiar with it.
1. Installing CocoaPods
Another great feature of CocoaPods is that it is distributed as a Ruby gem. This makes installing CocoaPods virtually painless. To install the CocoaPods gem, your system needs to have Ruby and RubyGems installed. Fear not because both Ruby and RubyGems are probably already installed on your computer.
Open a new Terminal window and type gem -v to determine if RubyGems is installed on your system. If you need help installing Ruby or RubyGems, Andrew Burgess wrote
about RubyGems on Nettuts+. In case you run into problems installing CocoaPods, chances are that Andrew's article has the solution to your problem.
Before installing CocoaPods, make sure to update RubyGems by running the following command on the command line:
gem update --system
Depending on your system configuration, it may be necessary to prefix this command with sudo.
If you want to read more about Ruby and Rubygems, Jeffrey Way wrote a nice article about
on Net Tuts+. The tutorial by Andrew Burgess that I mentioned earlier, is part of a in-depth series called . It is definitely worth checking out.
Installing CocoaPods is easy once Ruby and RubyGems are installed. Just run the following:
gem install cocoapods
Once installed, setup CocoaPods by running the pod setup command. During the setup process, the CocoaPods environment is formed and a .cocoapods directory is created in your home folder. This hidden folder contains all the available pod specifications or pod specs.
2. Starting With CocoaPods
Instead of explaining how CocoaPods works, it is far easier to show you by creating a simple Xcode project using CocoaPods. Open Xcode and create a new project based on the Empty Application template. Name the project CocoaPods and make sure to enable ARC (Automatic Reference Counting) for the project (figure 1).
Now that we created the project, we need to add a Podfile. A Podfile is similar to a Gemfile. It is a text file that contains information about the project and it also includes the project's dependencies, that is, the libraries that are managed by CocoaPods. Close the Xcode project and open a new Terminal window. Browse to the root of your Xcode project and create a new Podfile by running touch Podfile in the Terminal. The touch command updates the modified date of a file, but it creates the file for you if it doesn't exist, which is exactly what we want. Make sure to create the Podfile in the root of your Xcode project.
touch Podfile
Open the Podfile in your favorite text editor. At the time of writing this tutorial, the current version of CocoaPods is 0.16. In this version, it is required to specify the platform, iOS or OS X. This will no longer be necessary in the next version of CocoaPods (0.17). In this example, we tell CocoaPods that we target the iOS platform as shown below. It is possible to specify the project's deployment target, but this is optional. The default deployment target is 4.3 for iOS and 10.6 for OS X.
platform :ios, '6.0'
With the platform specified, it is time to create the list of dependencies for the project. A dependency consists of the keyword pod followed by the name of the dependency or pod. A pod is just like a gem, a dependency or library that you wish to include in a project or application. You can optionally specify the version of the dependency as shown below.
pod 'SVProgressHUD', '0.9'
By omitting a pod's version number, CocoaPods will use the latest version available (that is what you want most of the time). You can also prefix the version number with a specifier to give CocoaPods more control over which version to use. The specifiers are mostly self explanatory (&, &=, &, &=), but one specifier, ~&, might seem odd if you are not familiar with RubyGems. I'll explain what ~& means in the example shown below. The pod specification shown below indicates that the version of the AFNetworking library should be between 1.0.1 and 1.1 but excluding the latter. This is very useful if you want to give CocoaPods the ability to update a project's dependencies when minor releases (bug fixes) are available, but exclude major releases that can include API changes that might break something in your project.
pod 'AFNetworking', '~& 1.0.1'
A dependency declaration has a lot more configuration options, which can be set in the Podfile. If you want to work with the bleeding edge version of a library, for example, you can replace a pod's version number with :head as shown below. You can even tell CocoaPods what source to use by specifying the git repository or referring CocoaPods to a local copy of the library. These are more advanced features of CocoaPods.
pod 'AFNetworking', :head
pod 'SVProgressHUD', :git =& '/samvermette/SVProgressHUD'
pod 'ViewDeck', :local =& '~/Development/Library/ViewDeck'
With our list of dependencies specified, it is time to continue the setup process. Update the Podfile as shown below and run pod install in the Terminal. Make sure to run this command in the root of your Xcode project where you also created the project's Podfile.
platform :ios, '6.0'
pod 'ViewDeck', '~& 2.2.2'
pod 'AFNetworking', '~& 1.1.0'
pod 'SVProgressHUD', '~& 0.9.0'
pod 'HockeySDK', '~& 3.0.0'
pod install
CocoaPods inspects the list of dependencies and installs each dependency as specified in the project's Podfile. The output on the command line shows you what CocoaPods is doing under the hood. The last two lines are especial CocoaPods creates an Xcode workspace and adds our project to that workspace. It also creates a new project named Pods, adds the listed dependencies to that project, and statically links that with a library. The newly created Pods project is also added to that same workspace (figure 2).
Resolving dependencies of&code&./Podfile'
Updating spec repositories
Cocoapods 0.17.0.rc7 is available.
Resolving dependencies for target&code&default' (iOS 6.0)
Downloading dependencies
Installing AFNetworking (1.1.0)
Installing HockeySDK (3.0.0)
Installing SVProgressHUD (0.9)
Installing ViewDeck (2.2.5)
Generating support files
11:13:54.663 xcodebuild[] XcodeColors: load (v10.1)
11:13:54.665 xcodebuild[] XcodeColors: pluginDidLoad:
[!] From now on use&code&CocoaPods.xcworkspace'.
Integrating&code&libPods.a' into target&code&CocoaPods' of Xcode project&code&./CocoaPods.xcodeproj'.
When running the pod install command, CocoaPods tells us that we should use the CocoaPods.xcworkspace from now on. Xcode workspaces are a key component of how CocoaPods works. An Xcode workspace is a container that groups one or more Xcode projects, which makes it easier to work with multiple projects. As we saw earlier, CocoaPods creates a new project for you, named Pods, and it automatically adds this project to a new Xcode workspace. The project that we started with is also added to this workspace. The key advantage is that your code and the project's dependencies are strictly separated. The dependencies in the Pods project are statically linked with a library that you can see in the Build Phases tab of our project (figure 3). It is important thing to remember to use the workspace created by CocoaPods instead of the project we started with. Our project is now ready for us and we can start using the libraries specified in the project's Podfile.
3. Updating Dependencies
It is obvious that CocoaPods makes it easier to quickly set up a project with several dependencies. However, updating dependencies becomes easier as well. If one of your project's dependencies received a major update and you want to use this update in your project, then all you need to do is update your project's Podfile and run pod update on the command line. CocoaPods will update your project's dependencies for you.
4. Command Line
The CocoaPods gem has many more tricks up its sleeve. Even though you can use the
website to browse the list of available pods, the CocoaPods gem also lets you list (list) and search (search) the available pod specs. Open a new Terminal window and enter the command pod search progress to search for libraries that include the word progress. The advantage of searching for pods using the command line is that you only see the information that matters to you, such as the pod's source and the available versions.
Run the pod command (without any options) to see a complete list of available options. The CocoaPods manual is excellent, so make sure to read it if you run into problems or have any questions.
Conclusion
You should now have a basic understanding of CocoaPods so that you can use CocoaPods in your development. Once you start using CocoaPods, chances are that you won't be able to live without it. Even though I had heard of CocoaPods many times, it took me some time to make the transition. However once I started using CocoaPods, I haven't created a single project without it. I am sure you'll love it once you've given it a try. Not only will it save you time, it will also make your life as a developer a bit easier.
AdvertisementDifficulty:BeginnerLength:ShortCategories:Translations:Envato Tuts+ tutorials are translated into other languages by our community members&you can be involved too!Powered byAbout Bart Jacobs runs Code Foundry, a mobile and web development company based in Belgium and writes about iOS development on . Bart is also the mobile editor of Tuts+.AdvertisementWhat Would You Like to Learn? to the content editorial team at Envato Tuts+.Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them, it only takes a minute:
I just upgraded my old project to new iOS 7. It was already using Cocoapods. I compile and run and everything works fine on the simulator and the device. I tried to archive it using Xcode and I get the following error.
ld: library not found for -lPods
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Any ideas!
The architecture for the Pods project is set as the following:
Standard architectures (armv7,armv7s)
Cocoapods has been removed from my project. Everything is good now!
3,7711863136
1,15231436
Sounds like you just needed to update cocoapods. For anyone else who doesn't want to solve the problem by simply removing cocoapods from your project, do this:
Check your version of cocoapods:
pod --version
If it's less than 0.25.0, you need to do an update (don't forget "sudo" if necessary):
gem update cocoapods
Make sure your pods are updated:
pod install
Finally, open your .xcworkspace file.
You should be good to go.
I had this problem when experimenting with adding CocoaPods to an existing project.
It turned out that CocoaPods got the Architectures setting right, but missed on the Build Active Architecture Only setting. Both must be in perfect sync with your main project, or it will fail when building for a real device (at least if you got more than one ARM arch, which you usually do (armv7, armv7s and now arm64)).
Solved the problem for me, hopefully this will help others with a similar problem.
12.4k12976
I just fixed this issue in my workspace. In my case, it wasn't related to upgrading to iOS 7; instead, it was related to archiving for App Store submission. I created an App Store configuration (a duplicate of the Release configuration), and I was trying to use the App Store configuration for the Archive action (configured under Product > Scheme > Edit Scheme... > Archive > Build Configuration). The problem was that I had created an App Store configuration for my app's project, but I hadn't created an App Store configuration for the Pods project (the project that CocoaPods adds to your app's workspace). Once I did this (again, just a duplicate of the Release configuration), the Archive action succeeded.
The solution of @john doe (owner of this thread) is correct, you must set up CocoaPods for your project first by running
pod install
Variety of reasons why is this happening. This page is really helpful:
For some reason, I changed the workspace build location to Legacy. Changing it back to Custom: Relative to Derived Data solved it for me!
Try to remove arm64 from Build Setting -> Architectures (armv7, armv7s)
Set Build Active Architectures Only to NO
Worked for me just now.
cocoapods version 0.34.1
I had different problem - dublicate files.
Maybe you have dublicates in your project too. Like the ones from Pods and the other are old files which you didn't delete before you start using Cocoapods.
Double check them.
set the architecture of pods.
Click on Pods>Build Settings>Architecturs>armv7,armv7s
Your Answer
Sign up or
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Post as a guest
By posting your answer, you agree to the
Not the answer you're looking for?
Browse other questions tagged
Upcoming Events
Stack Overflow works best with JavaScript enabledCocoaPods的使用(管理iOS项目中第三方开源代码) - 流水年华 - 推酷
CocoaPods的使用(管理iOS项目中第三方开源代码) - 流水年华
sudo gem install cocoapods
命令解释: 用gem安装cocoapods工具包
输入这行命令后,会让你
输入电脑密码
接下来就是一大堆安装操作,耐心等待。
然后会出现下面的情况
Installing ri documentation for open4-1.3.4
Parsing documentation for cocoapods-0.33.1
Installing ri documentation for cocoapods-0.33.1
18 gems installed
接着输入下面命令
成功后会出现下面情况
Setting up CocoaPods master repo
Setup completed (read-only access)
就这样,cocoapods就安装成功了。
一共两行命令:
sudo gem install cocoapods
如果出现其他意外情况,请自行百度。
2 . cocoapods的简单使用
pod search afnetworking
命令解释: 在pods库中搜索包含&afnetworking&字样的第三方框架
搜索的结果中会包含:
(1)框架主要功能
(2)POD配置文件中的格式
(3)开发者主页
(4)开源源代码仓库URL,大多存放在Github
(5)版本历史
(6)其他辅助功能
示例搜索结果:
-& AFNetworking (2.3.1)
A delightful iOS and OS X networking framework.
pod 'AFNetworking', '~& 2.3.1'
- Homepage: /AFNetworking/AFNetworking
- Source: /AFNetworking/AFNetworking.git
- Versions: 2.3.1, 2.3.0, 2.2.4, 2.2.3, 2.2.2, 2.2.1, 2.2.0, 2.1.0, 2.0.3,
2.0.2, 2.0.1, 2.0.0, 2.0.0-RC3, 2.0.0-RC2, 2.0.0-RC1, 1.3.4, 1.3.3, 1.3.2,
1.3.1, 1.3.0, 1.2.1, 1.2.0, 1.1.0, 1.0.1, 1.0, 1.0RC3, 1.0RC2, 1.0RC1,
0.10.1, 0.10.0, 0.9.2, 0.9.1, 0.9.0, 0.7.0, 0.5.1 [master repo]
- Sub specs:
- AFNetworking/Serialization (2.3.1)
- AFNetworking/Security (2.3.1)
- AFNetworking/Reachability (2.3.1)
- AFNetworking/NSURLConnection (2.3.1)
- AFNetworking/NSURLSession (2.3.1)
- AFNetworking/UIKit (2.3.1)
-& AFNetworking+AutoRetry (0.0.4)
Auto Retries for AFNetworking requests
pod 'AFNetworking+AutoRetry', '~& 0.0.4'
- Homepage: /shaioz/AFNetworking-AutoRetry
- Source: /shaioz/AFNetworking-AutoRetry.git
- Versions: 0.0.4, 0.0.3, 0.0.2, 0.0.1 [master repo]
等等相关的
如果不确认某一个框架是否可用时,可以先去Github上看一下
3.cocoapods在项目中的使用
-&在xcode中新建项目
-&打开终端
& & -&cd 项目目录
& & -&touch Podfile
-&open -e Podfile
在打开的文本中输入诸如以下内容
platform :ios, '7.0'
pod 'AFNetworking'
保存退出,回到终端
-&pod install
强烈建议在家里的网络操作。
成功后终端会出现类似于下面的命令
Analyzing dependencies
Downloading dependencies
Installing AFNetworking (2.3.1)
Generating Pods project
Integrating client project
[!] From now on use `cocoapod测试.xcworkspace`.
然后执行终端命令
会看到多了几个文件:
localhost:cocoapod测试 yangyang$ ls
cocoapod测试.xcodeproj
Podfile.lock
cocoapod测试.xcworkspace
cocoapod测试Tests
cocoapod测试
添加完成之后,双击 xxx.xcworkspace即可
○所有项目中使用的第三方库的相关配置已经全部完成
○注意:使用Pods配置的项目,在#import头文件时,需要使用&&&&
○ #import &AFNetworking.h&
双击xxx.xcworkspace打开项目目录,类似如下。
4.添加或升级第三方库
升级:用终端打开当前项目目录,然后在当前目录下输入命令 -&pod update
添加:与上面类似,用终端打开项目里的那个文件,添加新的第三方库,然后执行命令 -&pod install
5.GEM常用命令
添加gem的源
gem sources -a
gem sources –l
gem自身升级
sudo gem update –system
查看当前版本
gem –version
清除过期的gem
gem cleanup
gem install ruby
gem uninstall ruby
更新本地安装的包
gem update
列出本地安装的包
6.写在最后
本文只是对cocoapod的简单介绍,详细的介绍,大家可以参考唐巧的博客文章&
用CocoaPods做iOS程序的依赖管理
已发表评论数()
已收藏到推刊!
请填写推刊名
描述不能大于100个字符!
权限设置: 公开
仅自己可见
正文不准确
排版有问题
没有分页内容
视频无法显示
图片无法显示当前访客身份:游客 [
当前位置:
osx10.10 &升级后cocoapods不能用了,重新安装啥的都提示成功,但是pod search就报错,有谁遇到跟我一样的问题吗?
MacBook-Pro:~ wuyinchun$ pod search
/Library/Ruby/Site/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- xcodeproj/prebuilt/universal.x86_64-darwin14-2.0.0/xcodeproj_ext (LoadError)
from /Library/Ruby/Site/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Library/Ruby/Gems/2.0.0/gems/xcodeproj-0.17.0/lib/xcodeproj/ext.rb:6:in `rescue in &top (required)&'
from /Library/Ruby/Gems/2.0.0/gems/xcodeproj-0.17.0/lib/xcodeproj/ext.rb:3:in `&top (required)&'
from /Library/Ruby/Site/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Library/Ruby/Site/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Library/Ruby/Gems/2.0.0/gems/xcodeproj-0.17.0/lib/xcodeproj.rb:30:in `&top (required)&'
from /Library/Ruby/Site/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Library/Ruby/Site/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Library/Ruby/Gems/2.0.0/gems/cocoapods-0.33.1/lib/cocoapods.rb:2:in `&top (required)&'
from /Library/Ruby/Site/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Library/Ruby/Site/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Library/Ruby/Gems/2.0.0/gems/cocoapods-0.33.1/bin/pod:32:in `&top (required)&'
from /usr/bin/pod:23:in `load'
from /usr/bin/pod:23:in `&main&'
共有2个答案
<span class="a_vote_num" id="a_vote_num_
不会升级....
--- 共有 1 条评论 ---
(1年前)&nbsp&
<span class="a_vote_num" id="a_vote_num_
/questions//cocoapods-with-xcode-6-and-10-10-yosemite
更多开发者职位上
有什么技术问题吗?
wycdavi...的其它问题
类似的话题

我要回帖

更多关于 如何使用cocoapods 的文章

 

随机推荐