[Swift] How to link the app with Firebase


When creating an app, we often use the login function. There are methods for logging in using your Apple ID and logging in using Twitter and Facebook.

This time, we will simplify their implementation and manage accounts after login. I will describe the procedure to link Firebase and the application that can be done.

The actual login implementation is introduced in a separate article. -Implement Twitter login function using Firebase UI

environment ・ Swift version 5.3 ・ XCode version 12.3 CocoaPods version 1.10.1

Implementation method

Qiita seems to have a fixed amount of images that can be posted in a month, so I would like to make the image as minimal as possible. I'm sorry···.

App creation

Create an app that implements the login function. This time, I created it with the project name ** SampleAppleLogin **.

Make a copy of the ** Bundle Identifier ** in the image. スクリーンショット 2021-01-14 16.28.22.jpg

Firebase new project creation

Create a new project in Firebase.

After accessing the Firebase console, click + Add Project -> Specify the project name and click "Continue" -> Enable Google Analytics for this project disableto create a project ->You have created a project. Click "Continue" when `is displayed

Firebase and app integration

Click the iOS button from Project Overview to add the app. スクリーンショット 2021-01-14 16.39.37.jpg

① Since there is a field to enter iOS bundle ID in the application registration, Copy and paste the Bundle Identifier of the app you just created here.

Other inputs are optional, so click Next.

Click GoogleService-Info.plist to download and click Next スクリーンショット 2021-01-14 16.43.12.jpg

Subsequent items will be set later, so Go to "Next"-> "Next"-> "Proceed to Console".

Now that you have registered the app on Firebase, Perform the process to link with Firebase on the application side.

Click the magnifying glass mark at the top right of the screen. (Or command + spacebar) スクリーンショット 2021-01-14 16.47.05.jpg A search field will appear. Enter "Terminal" and press Enter.

First, move the directory.

I move the directory with the cd command. Enter the PATH of the app you created earlier as the destination. In my case, the command is as follows.

If you are not sure, drag and drop the created app folder.

$ cd Desktop/project/SampleAppleLogin 

Next, create a Podfile.

$ pod init

Make sure the podfile is created just in case. In my case, the Podfile was created and it was in the following state.

$ ls
Podfile				SampleAppleLogin		SampleAppleLogin.xcodeproj

Edit the podfile.

$ vi Podfile

Add the installation target. There are two things to add.

pod 'FirebaseUI'
pod 'Firebase'

You need to be in edit mode first, so press i. Then you will see --INSERT -- on the bottom left.

In that state, you can enter characters.

I think that it will be as follows if I add it. (The contents are slightly different depending on the version.)

# Uncomment the next line to define a global platform for your project
# platform :ios, '9.0'

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

  # Pods for SampleAppleLogin
  pod 'FirebaseUI'   //add to
  pod 'Firebase'   //add to


Since it is necessary to save the file after adding, Press esc to cancel edit mode, then press: wq in order to save.

Then install it.

$ pod install

If no error occurs, it's OK!

If it occurs, please try google with the error content. (Basically, there should be no error.)

I close Xcode once and open the app from Finder. At this time, open the file with project name.xcworkspace.

Next, I downloaded it when I created the project in Firebase, Place the GoogleService-Info.plist in your app.

Place it in the same hierarchy as ViewController.swift etc. スクリーンショット 2021-01-14 17.11.29.jpg

If you click GoogleService-Info.plist, the screen in the middle will change. Copy the value in the value column of the row REVERSED_CLIENT_ID in it.

I think the content is com.googleuser ~.

If you click the project name on the top level, the screen in the middle will change. スクリーンショット 2021-01-14 17.17.13.jpg Select Info from the tags. Open the URl Types at the bottom and press+to add.

Paste the one you just copied into the URL Schemes in the upper right.

Then open AppDelegate.swift and edit it as below.


import Firebase    //add to

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    // Override point for customization after application launch.
    FirebaseApp.configure()    //add to
    return true

at the end

This article was planned to implement the login function in Firebase UI, so I have installed the Firebase UI with CocoaPods.

If you log in the other way, you may not need to install it, so Follow that method.

Also, so far, only cooperation has been completed, so You need to implement the actual login function.

The article about that is below. -Implement Twitter login function using Firebase UI

Thank you for watching until the end.

Recommended Posts

[Swift] How to link the app with Firebase
How to add sound in the app (swift)
[Swift] How to get the document ID of Firebase
[Swift] How to implement the countdown function
How to overwrite Firebase data in Swift
[Swift] How to display when the quiz app answers correctly [Beginner]
[Swift] How to implement the Twitter login function using Firebase UI ①
[Swift] How to implement the Twitter login function using Firebase UI ②
How to interact with a server that does not crash the app
[Swift] How to implement the LINE login function
[swift5] How to implement the Twitter share function
[Swift] How to implement the fade-in / out function
[Rails] How to apply the CSS used in the main app with Administrate
[swift5] How to change the color of TabBar or the color of item of TabBar with code
[swift5] How to transition from the app to an external site by specifying the URL
How to implement UICollectionView in Swift with code only
How to change the action with multiple submit buttons
How to run the SpringBoot app as a service
I want to dark mode with the SWT app
Organized how to interact with the JDK in stages
[Swift] Use UserDefaults to save data in the app
How to get started with creating a Rails app
[Swift] How to use UserDefaults
How to use Swift UIScrollView
How to number (number) with html.erb
How to update with activerecord-import
How to take a screenshot with the Android Studio emulator
Uppercase only the specified range with substring. (How to use substring)
[With back tricks] How to introduce React to the simplest Rails
How to specify db when creating an app with rails
How to make an app using Tensorflow with Android Studio
How to deal with the error ERROR: While executing gem ... (Gem :: FilePermissionError)
[Swift] How to install Firebase ~ How to use Realtime Database & Cloud Firestore
Learn how to customize the Navigation Bar from the sample app
How to change the file name with Xcode (Refactor Rename)
How to use the link_to method
How to scroll horizontally with ScrollView
How to use the include? method
How to use the form_with method
How to get started with slim
How to enclose any character with "~"
How to use the wrapper class
How to use mssql-tools with alpine
[Swift] How to use SwiftLint (cocoapods)
[Swift] How to use Unwind segue
[Swift] How to send a notification
Follow the link with Selenium (Java)
How to get along with Rails
How to add the delete function
[Swift] How to replace multiple strings
How to start Camunda with Docker
[Swift] How to dynamically change the height of the toolbar on the keyboard
I want to create a chat screen for the Swift chat app!
[Swift5] How to get an array and the complement of arrays
[Swift 5] Processing and precautions for transitioning to the iOS settings app
[Tips] How to solve problems with XCode and Swift for beginners
[Swift UI] How to get the startup status of the application [iOS]
[Note] How to restart the Windows container set up with docker-compose
How to use MinIO with the same function as S3 Use docker-compose
How to crop an image with libGDX
[Swift] How to pass the Label value in the selected collectionViewCell to the destination TextField