Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Firebase Cookbook

You're reading from   Firebase Cookbook Over 70 recipes to help you create real-time web and mobile applications with Firebase

Arrow left icon
Product type Paperback
Published in Nov 2017
Publisher Packt
ISBN-13 9781788296335
Length 288 pages
Edition 1st Edition
Arrow right icon
Author (1):
Arrow left icon
Houssem Yahiaoui Houssem Yahiaoui
Author Profile Icon Houssem Yahiaoui
Houssem Yahiaoui
Arrow right icon
View More author details
Toc

Table of Contents (15) Chapters Close

Preface 1. Firebase - Getting Started FREE CHAPTER 2. Firebase Real-Time Database 3. File Management with Firebase Storage 4. Firebase Authentication 5. Securing Application Flow with Firebase Rules 6. Progressive Applications Powered by Firebase 7. Firebase Admin SDK 8. Extend Firebase with Cloud Functions 9. We’re Done, Let’s Deploy 10. Integrating Firebase with NativeScript 11. Integrating Firebase with Android/iOS Natively 12. Hack Application's Growth 13. Adding Analytics and Maximizing Earnings 14. Firebase Cloud FireStore

Integrating Firebase in iOS applications

Integrating Firebase our iOS application involves adding the Firebase package similar to any other package you have probably worked with in the past.

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:

  1. Create a new project or open your already created project (Figure 17):
Figure 17: Xcode project opening/creation
  1. 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.
In our application--or when it comes to an example provided in this book regarding Firebase and iOS--we will work with Swift instead. It's just a personal preference, but you can use the one that suits you best.
Figure 18: Xcode project creation

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.

  1. 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).
Figure 19: Xcode project creation
  1. 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.
  2. 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).
Figure 20: Firebase GoogleService-info.plist download
  1. Now simply copy and paste that file into your project (Figure 21):
Figure 21: Firebase GoogleService-info.plist in our application.
  1. 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
To download and install CocoaPods on your macOS development machine, please follow the steps mentioned on the official website: https://guides.cocoapods.org/using/getting-started.html.

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.

  1. Now, you will need to edit the Podfile using your favorite code or text editor and add the following line:
      pod 'Firebase/Core'
  1. 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.

  1. Now, instead of your regular project, open another special project extension, as the following command shows:
       ~/project-directory ~> open project-name.xcworkspace
  1. 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
  1. Now, in the didFinishLaunchingWithOptions method, add the following code:
      FIRApp.configure()

Congratulations! You've successfully integrated Firebase with your iOS application.

You have been reading a chapter from
Firebase Cookbook
Published in: Nov 2017
Publisher: Packt
ISBN-13: 9781788296335
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image