Tuesday, May 16, 2017

How to setup Cocoapods in XCode for iOS Apps...? How to add third party Libraries using Cocoa pods in XCode

Setup Cocoapods : Open terminal and run this command to install Pods:


sudo gem install cocoapods


Enter admin password. This could take a few minutes of your time and then it will show green message "cocoapods installed successfully in your mac machine".
If you are getting any error with XCode 6 or later like developer path is missing. First run this command in terminal:


sudo xcode-select -switch /Applications/Xcode6.app (or your XCodeName.app)


If you still able to see same problem, you can do small hack like renaming the Xcode 6 to default. It is because terminal is not able to find path of your Xcode.


After running these commands you should have successfully installed CocoaPods in your mac machine. Now you can setup Pod with your Xcode project.


How to setup POD for your Xcode project:


1. Open Terminal


2. Change directory to your Xcode project root directory (where your ProjectName.xcodeproj file is placed).


Ex: cd "path of your project xcodeproj file" or Just drag and drop the project file into terminal.


3. $ pod setup : (Setting up CocoaPods master repo)
If successful, it will show : Setup completed (read-only access). So, you are ready now. Now lets install libraries in your Xcode project using Pods.


Steps to add/remove/update libraries in pod:


1. Open Terminal


2. Change directory to your Xcode project root directory (where your ProjectName.xcodeproj file is placed).


3. $ touch podfile (This will create a blank text file)


4. $ open -e podfile (This will open created blank text file)


5. Add your library names in that text file. platform :ios, '7.0' target 'Inspections' do pod 'AFNetworking', '~> 2.6.0' pod 'CocoaLumberjack', '~> 2.0.1' pod 'Crashlytics' pod 'Fabric' pod 'Flurry-iOS-SDK', '~> 7.1.1' pod 'skpsmtpmessage', '~> 0.0.1' pod 'ZipArchive', '~> 1.4.0' pod 'Localytics', '~> 3.8.0' end


NOTE: Use ( control + ” ) button to add single quote at both end of library name. It should be shown as straight vertical line. Without using control button it shall be added as curly single quote which will give error while installation of file.


6. Save and close this text file. Now libraries are setup and you have to install/update it.


7. Go to your terminal again and run this command: $ pod install (to install/update libraries in pod).


You should see output similar to the following:


Updating spec repo `master’
Installing “Library name” (1.2.2)..
Generating support files
After successful downloading/installation of any single library, It will generate ProjectName.xcworkspace in your project root directory. From now use this workspace to open your project. When you open your project work space you will see Pod is also added as another Xcode project with your Xcode project. If you open Pod it will show all libraries.


Libraries downloaded using Pod will only work only if you open workspace file.
For your next project you don’t need to install the cocoa pod again in your mac machine just open the terminal and setup the Pod in root directory of your Xcode project and always remember these 3 commands :
  • 1. $ touch podfile
  • 2. $ open -e podfile
  • 3. $ pod install
To update Pod libraries : $ pod update
To check POD version : $ pod –version


To update CocoaPods : $ gem install cocoapods or use sudo at start if getting error “You don’t have write permissions for the /Library/Ruby/Gems/2.0.0 directory.”

No comments:

Post a Comment