id: 12707    nodeId: 12707    type: General    point: 108.0    linkPoint: 1.0    maker: cella    permission: linkable    made at: 2020.03.24 05:09    edited at: 2022.01.07 08:24
Add Firebase to your iOS project
https://firebase.google.com/docs/ios/setup
1.
Make an Xcode project. Just after creation, quit Xcode.
$ pod init
$ modify Podfile according to the Google Firebase guidelines like:
--------8<--------
# Uncomment the next line to define a global platform for your project
platform :ios, '10.0'

target 'ReadWrite1' do
# Comment the next line if you don't want to use dynamic frameworks
use_frameworks!

# Pods for ReadWrite1
pod 'Firebase/Auth'
pod 'Firebase/Firestore'
pod 'FirebaseFirestoreSwift'
pod 'Firebase/Analytics'

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

target 'ReadWrite1UITests' do
# Pods for testing
end

end
--------8<--------

$ pod install
Open ProjectName.xcworkspace from now on. Not ProjectName.xcodeproj.

2. But, "pod init" causes an error:
/usr/local/Cellar/ruby/3.0.1/lib/ruby/3.0.0/rubygems.rb:281:in `find_spec_for_exe': can't find gem cocoapods (>= 0.a) with executable pod (Gem::GemNotFoundException)
from /usr/local/Cellar/ruby/3.0.1/lib/ruby/3.0.0/rubygems.rb:300:in `activate_bin_path'
from /usr/local/lib/ruby/gems/2.7.0/bin/pod:23:in `<main>'

I tried:
$ brew reinstall cocoapods
But still the same problem.

I tried:
$ gem install cocoapods
It works.

3. If the project is changed after the creation, it might be needed to remove some files:

Note: during "pod install", Xcode should be quit.
Even the following steps may be needed:
Quit Xcode.
Delete project's temp files located at ~/Library/Developer/Xcode/DerivedData
Delete ProjectName.xcworkspace
Delete Podfile.lock file and Pods folder
Run pod install.
Open the newly created ProjectName.xcworkspace file and build. <== Note: can be done with "$ open ProjectName.xcworkspace"

Note that xcworkspace is different from xcodeproj.

Return to Add Firebase to your iOS project