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 a 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.
Next step would be to create a Firebase Project.
Create a Firebase Project
Go to Firebase and log in with your Google account if you have it already, otherwise create a gmail account.
Once you’ve logged in, Create a new project by clicking + Add Project button from the Firebase Console.
If you have a few project 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 + Add Project button.
Make sure to add a Project Name and select the checkbox of terms and click Create project.
This is will take a few seconds 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 Register App.
To set the iOS Bundle ID input field , hop over to your Xcode project and select root of the project folder from the Project Navigator pane at the top left,
Then, Choose General → Identity → Bundle Identifier. Copy it.
Head back over to Firebase and past 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 the .plist file that you’ve downloded from downloads folder to Xcode Project Navigator at the root level.
When you let go, you will get a pop-up window and make sure that 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 is added sibling to info.plist file.
Head back to Firebase Console Firebase to your iOS page and click next to the second step which will bring the next step Add FirebaseSDK.
Add Firebase SDK
To do that, you would 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 cocoapods 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 and
if you navigate to your Xcode project folder in Finder, you will be able 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 below code 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 downloading Firebase dependencites and integrating to your Xcode project.
Once it’s done, you can see a few files added to the project when looking the project folder in Finder.
Now onwards, you would 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 and open up .xcworkspace file to launch the project.
As you can see on the project navigator, there are two sections one is an acutal project files and another one is pod files.
Next step is to add initialization code from Firebase to Xcode.
Add initialization code
Open up FirebaseiOSDemo folder form 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 return true line in the AppDelegate.file as well.
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 Congratulations, you’ve successfully added Firebase to your app!
At this stage, Firebase has been added to your Xcode project.
There you have it 🙂
What are the Firebase Products that you’re intend to use in your iOS App? Mine is Firebase Authentication for User Authentication, Firestore for Database and Cloud Functions for Back-end code.
NEXT → iOS Facebook Login Using FirebaseUI in 20 MINS