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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM