Do you think IIT Guwahati certified course can help you in your career?
No
Introduction
Firebase allows developers to create mobile and online applications. This is a backend platform that can use to create Web, Android, and iOS applications. It includes a real-time database, many APIs, multiple authentication methods, and a hosting platform. It is a web service that offers us a cloud-based infrastructure that allows us to save and retrieve data from the Google Web Service. We don't have to worry about keeping our servers up to date or writing server-side code.
In this blog, we will create a real-time chat application using Firebase. The most critical part of developing a messaging app is learning how to set up Firebase for iOS apps and save chat data into the database. Using the Authentication feature on Firebase, we will provide sign-up and login functionality to the user in this iOS app.
In this blog, we will be working on an app template; rather than creating the interface of an actual application, we will use a downloaded one. You can also create an application instead of downloading it, and the following process will remain the same in both cases.
Create and configure a new Firebase iOS Project
Create a new project on Firebase by logging in with your Google account (Skip this step if you already have a Firebase project for your chat app). This will prompt us to give the project a name, as illustrated below:
2. To continue setting up the Firebase, click Continue. The following window, as seen below, asks us to enable Google Analytics in the project:
3. To continue the procedure, go to step 3 and select a Location. We're through with the Firebase project after choosing a location from the dropdown menu.
4. Our project is now complete. This project requires us to include our iOS app. To do so, go to the project dashboard panel and click iOS, as shown below.
5. This will prompt us to input the bundle id, App nickname, and App Store Id for the application. The nickname and store id, on the other hand, are optional, but we must provide the bundle id. You can find your bundle identifier in the General tab for your app's primary target in Xcode.
6. From the dashboard, download the GoogleService-info.plist file and add it to the XCode project.
7. Add the Firebase SDK to the project now. The steps to add the Firebase SDK are shown in the figure below:
8. Add the initialization code below to your app's main entry point to connect Firebase when it starts up:
9. We're ready to use Firebase in our iOS app once we add the initialization code to the AppDelegate. To connect to Firebase, create an XCode project and follow the outlined procedures. Use the same bundle id that we used for our iOS app in Firebase.
Set up Firebase Realtime database
We'll need to set up a Realtime Database on Firebase to build our real-time chat application. To do so, go to the project console and select Realtime Database. As illustrated below, we will be prompted to create a database.
2. To make a database, click Create Database. The initial stage will ask us to select a country, which will be the United States by default. Select the United States and then press Next.
3. After clicking Next, we'll be asked to select the Database Rules, such as locked or test mode. For the time being, we'll start in test mode. To continue using the database, select test mode and click Enable.
4. Go to Realtime Database on the firebase console and verify the data to see if the data is being stored on the project dashboard. It will be shown something like this:
Since there is no data stored, we can see null.
Adding users to our app on Firebase
We'll now use the Firebase Authentication feature to add users to our project. Go to the Authentication section of the Firebase console for this. As illustrated below, it will prompt us to begin.
We need to enable the Sign-in option in our app once we've begun using the Authentication Feature. Several options are available; In our app, we will allow the Email/Password Sign-in mechanism. You can enable as many authentication methods as you like. To do so, go to the Edit icon and enable the option as indicated in the image below:
Build & Run the app with Xcode
Now that you've configured your Firebase backend and connected it to the app template, it's time to see the real-time chat app in action.
Open a terminal window, find the Podfile file (it's in the ChatApp folder in most cases), and run it to install the pods:
cd ~/path_to_downloaded_folder/ChatApp
#replace the path of the app in place of “path_to_downloaded_folder”
pod install
Note: If you don't already have Cocoapods, go to their website to get started.
2. When you run "pod install," a.xcworkspace file should appear in the same folder as Podfile. Double-click it, or use your terminal to type "open ChatApp.xcworkspace." This will launch Xcode and open your whole Swift project.
3. Click "Run" after selecting whatever simulator you wish to run (or plugging in your iPhone device). The Chat app will be installed on the selected device as a result of this action.
4. Create an account (email/password or Facebook Login) to play around with the app. In Firebase -> Authentication, you'll see the newly created account. You should now see the "users" table (under Database -> Firestore), which contains the newly created user information. However, the home screen will be empty, and you will be unable to look for any friends) - this is to be anticipated, as there are now no friendships.
5. To have a proper chat app, you'll need more users, so go ahead and create new accounts via the iOS app. In Firebase -> Authentication -> Add User, you can also manually create them.
Add the friendships between users.
To be able to develop chat rooms, you must first establish a few friendships among your users. On the Search page, add a few friends and then accept those friend requests from the accounts of the corresponding users. You can start conversing with people once you've added them to your Contacts tab. You may begin forming groups once you have at least two friends to group-chat with.
Integrating chat into my existing iOS app
When you open a chat room programmatically, you only need to perform the following to create a view controller that displays a chat room:
func openChatRoom() {
let user = ATCUser(firstName: "Test F", lastName: "Test L")
let channel = ATCChatChannel(id: "idc", name: "Group Test")
let uiConfig = ATCChatUIConfiguration(primaryColor: UIColor(hexString: "#0084ff"),
As you can see, you must identify the user who starts the chat room, as well as the channel (it can be a one to one conversation or a group chat; all it matters is its ID)
Frequently Asked Questions
What is Firebase?
Google's Firebase technology allows the creation of mobile and online applications. It is a web service that offers us a cloud-based infrastructure that will enable us to save and retrieve data from the Google Web Service. We don't have to worry about keeping our servers up to date or writing server-side code.
Is Firebase suitable for chat apps?
Yes, because building a chat app on Firebase is simple, and it's a great way to demonstrate the potential of real-time messaging and notifications. It includes a real-time database, many APIs, multiple authentication methods, and a hosting platform.
Is Firebase capable of handling a million users?
The firebase database can be used to run queries with limited sorting and filtering capabilities. Cloud firestore ensures automatic scaling and has a capacity of 1 million concurrent connections and 10,000 writes per second.
Which big companies use Firebase?
Firebase is used by several well-known companies. Alibaba, Lyft, Trivago, Venmo, and NPR are just a few examples.
Is Firebase free?
All of Firebase's products include a no-cost tier pricing model. Some products are free to use regardless of how much you use them. If you need a lot of usage from other products, you'll have to move your project to a paid-tier pricing plan.
Conclusion
In this article, we have discussed Firebase and learned how to build an app using the same. We have discussed all the steps to set up Firebase for an iOS-based real-time chatting application.