How To Add Firebase to Your iOS App Quickly ← [Updated 2020]
Adding Firebase to your iOS App in the first step before start using Firebase products such as Authentication, Database, Cloud Functions etc.
In this Firebase iOS tutorial, I will be walking you through how to connect Firebase to your iOS app using Swift Language with STEP by STEP instructions.
- Create an Xcode Project
- Create a Firebase Project
- Register App
- Download Config File
- Add Firebase SDK
- Add Initialization Code
- Run Your App to Verify installation
Create a New Xcode Project
Go ahead and open up Xcode and choose File → New → Project.
Then, Choose a Single View Application from the template pop-up window and click next.
Give it a project name of your choice and mine is FirebaseiOSDemo and make sure that the Language is set to Swift and Click Next,
Xcode will ask where to save the project and you can choose any location from your computer and Click Create.
The next step would be to create a Firebase Project.
Create a Firebase Project
Once you’ve logged in, create a new project by clicking + Add Project button from the Firebase Console.
If you have a few projects created already, you can see them along with + Add Project button on your Firebase Console page.
Firebase will bring a pop-up window when you hit the + Add Project button.
Make sure to add a Project Name and select the checkbox of terms and click Create Project.
It will take a few seconds to finish creating a new project. Once it’s done, click Continue to the Project Console.
Click the iOS icon that will be on the middle of the page.
If you do not see the iOS icon for some reason, you can go to the Firebase dashboard → Project Overview (at the top left) → click the gear icon → click Project Settings
If you scroll down, at the bottom, you can see the iOS icon.
Once you have clicked the iOS icon, you will be directed to the Add Firebase to Your iOS App page which has five steps to complete.
The first one is the Register App.
To set the iOS Bundle ID input field, hop over to your Xcode project and select the root of the project folder from the Project Navigator panel at the top left.
Then, choose General → Identity → Bundle Identifier. Copy it.
Head back over to Firebase and paste it in there. In my case com.softauthor.FirebaseiOSDemo.
App nickname and App Store ID input fields are optional, so I am going to leave them blank.
Click Register App.
Download Config File
At this stage, Firebase created .plist file. Go ahead download the
Download GoogleService-Info.plist file to your computer. In my case, it will be downloaded into my Downloads folder.
Move the .plist file that you’ve downloaded from the downloads folder to Xcode Project Navigator at the root level.
When you let go, you will get a pop-up window and make sure to copy items if needed and Add to targets are checked.
Then, click Finish.
At this stage, you can see the .plist file added to the project navigator.
Make sure that the GoogleService-Info.plist file added the sibling to info.plist file.
Head back to the Firebase Console, to your iOS page, and click next, which will bring you to the second step, Add FirebaseSDK.
Add Firebase SDK
To do that, you need to install CocoaPods if you haven’t already. Open up your Terminal → Run sudo gem install cocoapods command to install CocoaPods.
CocoaPods is a dependency manager for Swift and Objective-C which will help you to install third-party packages like Firebase to your Xcode project.
Once you have cocoa pods installed, the next step would be to create a Podfile.
To create that, open up a terminal window and navigate to the location of your Xcode project folder.
If you navigate to your Xcode project folder in Finder, you will be able to see the new file called PodFile added to the project.
Next, add Firebase Pod to the PodFile.
To add that, open up the PodFile and add the code below under # Pods for FirebaseiOSDemo and save the file.
Finally, go to Terminal and locate the Xcode project folder and run:
This will take a few seconds to download Firebase dependencies and integrate it into your Xcode project.
Once it’s done, you can see a few files added to the project when looking at the project folder in Finder.
From now onwards, you will need to use .xcworkspace to open up the project instead of using .xcodeproj.
Go ahead and close the Xcode project if you haven’t already done so, and open up .xcworkspace file to launch the project.
As you can see, on the project navigator, there are two sections: one is an actual project file and the other one is pod files.
The next step is to add the initialization code from Firebase to Xcode.
Add Initialization Code
Open up FirebaseiOSDemo folder from the project navigator → choose AppDelegate.swift file in which I will be adding two lines of code.
One is at the top:
Another one is inside didFinishLaunchingWithOptions() method but before the return true line in the AppDelegate.file.
Run Your App to Verify the Installation
Run your Xcode project by clicking the ► icon at the top or Cmd + R.
Then, go to Firebase and wait for a few seconds and you can see it! Congratulations, you’ve successfully added Firebase to your app!
At this stage, Firebase has been added to your Xcode project.
There you have it 🙂