iOS项目添加CocoaPods

iOS项目添加CocoaPods

 安装sudo gem install cocoapods

*如果发现半天没反应是因为Ruby的默认源使用的是cocoapods.org 但在国内阻挡了 cocoapods.org,
    可以将源换成淘宝的来解决这个问题,可以尝试换以下方法。
$ gem sources --remove https://rubygems.org/
//等有反应之后再敲入以下命令
$ gem sources -a http://ruby.taobao.org/




只有在终端中出现下面文字 说明成功
*** CURRENT SOURCES ***

http://ruby.taobao.org/

替换完ruby后 再次执行以下命令
$ sudo gem install cocoapods 
 
安装结束后再执行命令
$ pod setup 



安装完成后可以在Finder 中查找到以下目录 /Users/用户名/.cocoapods   
注:.cocoapods为隐藏文件
 

如果顺利可以在得到如下图所示的结果,Specs内有很多第三方库目录。
 

二. 项目中使用CocoaPods

1.创建Xcode项目工程

创建一个名称为test的xcode测试工程
 

2.创建Podfile文件

终端进入该文件夹
$ cd desktop/test
$ touch Podfile

3.打开创建的Podfile文件并添加内容,完成后保存。

platform :ios, '7.0' 
pod 'SBJson', '~> 4.0.0'

4.执行pod安装命令,命令行转到工程目录下执行以下命令

$ cd desktop/test $ pod install

等待5分中 太慢了 我也是醉了,下图是执行结果
 


在项目工程目录中会多出以下文件
 

5.可以用test.xcworkspace文件来进行开发   

原来的工程设置被更改,编译会报错 所以只能用test.xcworkspac来进行项目开发及管理。
 

三.问题

问题1: 如果$ pod install后长时间卡在 Analyzing dependencies  可能master内无内容

解决方法1:
  $ pod repo remove master
  $ pod setup  
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="font-size:12px;">//需要一段时间 耐心等待 结果如下图</span></span>
 
最后再到项目目录下执行
$ pod install
 
解决方法2:
到以下地址进行下载
https://github.com/CocoaPods/Specs
 
把下载后的文件放到master下
 

三. 参考资料

http://code4app.com/article/cocoapods-install-usage
https://guides.cocoapods.org
 
实例
platform :ios, '9.0'
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'

target 'saafRN_61' do
  # Pods for saafRN_61
  pod 'FBLazyVector', :path => "../node_modules/react-native/Libraries/FBLazyVector"  
  pod 'FBReactNativeSpec', :path => "../node_modules/react-native/Libraries/FBReactNativeSpec"
  pod 'RCTRequired', :path => "../node_modules/react-native/Libraries/RCTRequired"
  pod 'RCTTypeSafety', :path => "../node_modules/react-native/Libraries/TypeSafety"
  pod 'React', :path => '../node_modules/react-native/'
  pod 'React-Core', :path => '../node_modules/react-native/'
  pod 'React-CoreModules', :path => '../node_modules/react-native/React/CoreModules'
  pod 'React-Core/DevSupport', :path => '../node_modules/react-native/'
  pod 'React-RCTActionSheet', :path => '../node_modules/react-native/Libraries/ActionSheetIOS'
  pod 'React-RCTAnimation', :path => '../node_modules/react-native/Libraries/NativeAnimation'
  pod 'React-RCTBlob', :path => '../node_modules/react-native/Libraries/Blob'
  pod 'React-RCTImage', :path => '../node_modules/react-native/Libraries/Image'
  pod 'React-RCTLinking', :path => '../node_modules/react-native/Libraries/LinkingIOS'
  pod 'React-RCTNetwork', :path => '../node_modules/react-native/Libraries/Network'
  pod 'React-RCTSettings', :path => '../node_modules/react-native/Libraries/Settings'
  pod 'React-RCTText', :path => '../node_modules/react-native/Libraries/Text'
  pod 'React-RCTVibration', :path => '../node_modules/react-native/Libraries/Vibration'
  pod 'React-Core/RCTWebSocket', :path => '../node_modules/react-native/'

  pod 'React-cxxreact', :path => '../node_modules/react-native/ReactCommon/cxxreact'
  pod 'React-jsi', :path => '../node_modules/react-native/ReactCommon/jsi'
  pod 'React-jsiexecutor', :path => '../node_modules/react-native/ReactCommon/jsiexecutor'
  pod 'React-jsinspector', :path => '../node_modules/react-native/ReactCommon/jsinspector'
  pod 'ReactCommon/jscallinvoker', :path => "../node_modules/react-native/ReactCommon"
  pod 'ReactCommon/turbomodule/core', :path => "../node_modules/react-native/ReactCommon"
  pod 'Yoga', :path => '../node_modules/react-native/ReactCommon/yoga'

  pod 'DoubleConversion', :podspec => '../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec'
  pod 'glog', :podspec => '../node_modules/react-native/third-party-podspecs/glog.podspec'
  pod 'Folly', :podspec => '../node_modules/react-native/third-party-podspecs/Folly.podspec'



  permissions_path = '../node_modules/react-native-permissions/ios'
 
  pod 'Permission-BluetoothPeripheral', :path => "#{permissions_path}/BluetoothPeripheral.podspec"
  pod 'Permission-Calendars', :path => "#{permissions_path}/Calendars.podspec"
  pod 'Permission-Camera', :path => "#{permissions_path}/Camera.podspec"
  pod 'Permission-Contacts', :path => "#{permissions_path}/Contacts.podspec"
  pod 'Permission-FaceID', :path => "#{permissions_path}/FaceID.podspec"
  pod 'Permission-LocationAlways', :path => "#{permissions_path}/LocationAlways.podspec"
  pod 'Permission-LocationWhenInUse', :path => "#{permissions_path}/LocationWhenInUse.podspec"
  pod 'Permission-MediaLibrary', :path => "#{permissions_path}/MediaLibrary.podspec"
  pod 'Permission-Microphone', :path => "#{permissions_path}/Microphone.podspec"
  pod 'Permission-Motion', :path => "#{permissions_path}/Motion.podspec"
  pod 'Permission-Notifications', :path => "#{permissions_path}/Notifications.podspec"
  pod 'Permission-PhotoLibrary', :path => "#{permissions_path}/PhotoLibrary.podspec"
  pod 'Permission-Reminders', :path => "#{permissions_path}/Reminders.podspec"
  pod 'Permission-Siri', :path => "#{permissions_path}/Siri.podspec"
  pod 'Permission-SpeechRecognition', :path => "#{permissions_path}/SpeechRecognition.podspec"
  pod 'Permission-StoreKit', :path => "#{permissions_path}/StoreKit.podspec"






  target 'saafRN_61Tests' do
    inherit! :search_paths
    # Pods for testing
  end

  use_native_modules!
end

target 'saafRN_61-tvOS' do
  # Pods for saafRN_61-tvOS

  target 'saafRN_61-tvOSTests' do
    inherit! :search_paths
    # Pods for testing
  end

end
原文地址:https://www.cnblogs.com/chenzxl/p/13527953.html