Integrating Firebase our iOS application involves adding the Firebase package similar to any other package you have probably worked with in the past.
Integrating Firebase in iOS applications
Getting readyÂ
In order to create and integrate Firebase within your application, you will need to have a MacBook Pro or one of Apple's computer variants so that you can follow the upcoming steps; you will also need to install Xcode.
How to do it...
In order to create an iOS application, open Xcode and follow the given steps:
- Create a new project or open your already created project (Figure 17):
- In our case, we're about to start a new project called firebasecookbook. It's going to be based on the Xcode single-view application project template.
Don't forget to copy that Bundle Identifier, because we will need it in the next step. In this case, our Bundle Identifier is hcodex.firebasecookbook.
- Go to your Firebase dashboard and click on the Add Firebase to your iOS app button. After clicking on it, you will get a configuration model with some steps that will guide you in your Firebase iOS integration (Figure 19).
- Remember that bundle id or Bundle Identifier? Copy and paste that ID in its designated place and add a nickname for your application if you wish. Click on the REGISTER APP button.
- Next, we will need to download a special plist file called the GoogleService-info.plist file. This file will have all the necessary metadata that will be included in your project (Figure 20).
- Now simply copy and paste that file into your project (Figure 21):
- After we have finished the file download and file integration, let's just install some dependencies. In this process, we will use CocoaPods as our package manager. Head directly to your project using your terminal:
~ cd project-directory
~/project-directory ~> pod init
After you initialize your project with CocoaPods, you will find a newly created file named Podfile.
The Podfile is a specification that describes the dependencies of the targets of one or more Xcode projects.
- Now, you will need to edit the Podfile using your favorite code or text editor and add the following line:
pod 'Firebase/Core'
- Now, save the file, go back to your terminal, and write down the following command:
~/project-directory ~> pod install
This command will download and install all the required libraries and modules that Firebase needs to fire up within your application.
- Now, instead of your regular project, open another special project extension, as the following command shows:
~/project-directory ~> open project-name.xcworkspace
- We're one step behind. Now, in your application, go directly to your AppDelegate and simply import Firebase using the following code snippet:
import Firebase
- Now, in the didFinishLaunchingWithOptions method, add the following code:
FIRApp.configure()
Congratulations! You've successfully integrated Firebase with your iOS application.