All right. 1
So in this lesson, we're going to be setting up our project to be able to use Firebase. Firebase is a 2
all of one suite of tools that is backed by Google, and allows you to do lots of things, such as see what 3
all the crashes that are happening on your app, or store data in the Cloud, or authenticate users and 4
store their passwords and login information securely, as well as other things, such as incorporating 5
Google analytics or A/B split testing, load and loads of things essentially. 6
So in order to get started, you should sign into your Google account. And if you don't have one, then you 7
might have to set one up now. 8
Once you've signed in, you can go ahead and click on this button here to go to your console, and then 9
go ahead and click on this tab to add a new project. 10
It's going to start by asking you for your project name. 11
So I have lots of FlashChats as you can see in here, but I'm going to call this one Flash Chat iOS13. 12
And then go ahead and click continue. 13
Now, I'm actually going to switch off Google Analytics for this project just because it involves a lot 14
more testing and I actually don't need any of these features right now. 15
And then go ahead and click Create Project. 16
And once this is done, it will tell you that your new project is ready and you can go ahead and click 17
Continue. 18
So, now we're in the console for our Flash Chat iOS 13 project and we're going to go ahead and get started 19
by adding an iOS app which is what we have. 20
So click on that button and we're going to register our app. 21
Now, the first thing that I asked you is the iOS Bundle ID. So we should be able to find 22
the Bundle ID in the General tab for your app's primary target and Xcode. 23
What does that mean? 24
Well, if we head back into Xcode and we select our Flash Chat project, select Flash Chat iOS13 as 25
the Target, 26
then this is our Bundle identifier right here. 27
So go ahead and copy it. And make sure that yours is unique, so that you're not using co.appbrewery 28
because, otherwise, it might have difficulties registering you, 29
so be sure to replace this with your own unique name or your website. And then copy this entire string 30
over into this field right here. And then you can provide an app nickname or an App Store ID which 31
you wouldn't have one just yet. 32
It's when you've launched your app that you actually get this number. 33
These two are both optional. 34
So we're going to skip both those and click Register. Once our app has been registered, then you can go ahead 35
and click on this large button here to download the configuration file for your project. And this will 36
have to move into our Xcode project right here in the root directory of our Xcode project. 37
So you should see it down here, but you should also be to find it in your downloads. Now, a really important 38
tip right here is if you download more than one of these GoogleService-info.plist, see if I click 39
on this twice or I click on it from a different project, then what Apple actually does is it appends 40
at the end 41
this brackets one or brackets two depending on how many different versions you have of the same thing. 42
And when we add it to our project, it has to look identical to this. It has to say, 43
GoogleService-Info.plist. 44
It has been named exactly like this because it's what Firebase is going to look for. 45
So make sure that you haven't got any duplicates in your downloads. 46
And if you do, then just delete all of them and then download a fresh copy of your config file, and make 47
sure that when you look at it in the Finder, it doesn't have anything between the word info and .plist. 48
So, now that we've got it here, we're ready to add it to our project. 49
The easiest way to do this is to, first, navigate to our Xcode project. And notice how we're going to 50
drop it somewhere near the original Info.plist, and then let's bring up our Finder, so our downloads 51
folder, and then click and drag it just below the Info.plist, and make sure it says, "Copy items if 52
needed." 53
So check that and also check the Add to targets: Flash Chat, and then click Finish. 54
So, now that we've added our GoogleService-Info.plist, you should see it written exactly as 55
I have here. 56
And we're ready to move on to the next step which is to add the Firebase SDK using CocoaPods. 57
So this is Google's recommended way of working with Firebase. 58
And now that we know all about CocoaPods and we've already installed it, then we can simply add this 59
as a pod to our project. 60
Now, normally, if you've created a new Xcode project that doesn't have a pod file, then you would use 61
that keyword "pod init" in order to create a new pod file. 62
But in our case, because we've already got one right here in our Flash Chat project, we don't have to 63
do that. 64
All we need is to add the pod files that we need. 65
So sometimes I've noticed that this page changes, sometimes the Google team like to put the pods that 66
you might want, 67
other times, it gives you a URL. But either way, if you go ahead and head over to this link, and you 68
can see we're at this stage step four: adding the Firebase SDK. And we have to add the pods that we need. 69
But because Firebase has lots of different services, we don't want to add all of them. 70
We only want to add the ones that we're going to be using. 71
So right now, the only ones that I need are authentication and Cloud Firestore. 72
So I'm gonna go ahead and copy pod Firebase.Auth, 73
so command C, and then paste that in here just between this comment and the "end" keyword. 74
And I'm also going to add the pod Firebase/Firestorm. 75
So it's just these two that we need. 76
Now, I'm going to hit save, closed down my project, and then go ahead and run pod install. 77
So now back in our Terminal making sure that you're still within that parent folder Flash-Chat-iOS13, 78
and then we're going to run pod install. Hit enter. And it should pull down all of those codebases that we 79
need. 80
So the Firebase core module is gonna be incorporated automatically, as well as the authentication and 81
Firestore modules. 82
Now, this might take some time, 83
so just give it a little moment and let it do its thing. Now, you'll know that it's done once it says, 84
pod installation complete, and you see your prompt and the dollar sign again. 85
So you'll notice that it's actually installed a whole bunch of modules and this is because the FirebaseAuth 86
and FirebaseFirestore modules actually have dependencies, so other code and packages that they 87
themselves depend on. 88
So all of these things gets pulled down and added to your project. 89
So, now we're ready to get started working with Firebase, so you can close down Terminal and go back to 90
the Flash Chat Console and click Next. So it tells us to connect Firebase when your app starts up. 91
We have to add the initialization code to your main AppDelegate class. 92
So let's go ahead and do that in our project. 93
And remembering again that whenever we add dependencies using CocoaPods, we need to be working with 94
this white icon the xcworkspace, instead of the Xcode project. 95
So let's double click on this white icon and then go ahead and open up our AppDelegate.swift which 96
is under our Flash Chat project inside the Flash Chat folder. And right here, we've got something called 97
didFinishLaunchingWithOptions. And we're going to delete this comment and add the Firebase Initialization 98
code. 99
So first things first, we have to import the Firebase module into this file. 100
So let's go ahead and do that just below 101
Import UIKit. 102
Next, we have to add this line FirebaseApp.configure. 103
So let's click this to copy that line of code and paste it right here above where it says "return true." 104
Now, let's hit command B to make sure that everything's working properly and that our Firebase pods have 105
been incorporated without any errors. So this time building our project will take a little bit longer 106
than before because there's a lot more dependencies in our project now because we're building a more 107
serious app. 108
So just give it some time and maybe grab a cup of tea and it should be done shortly. 109
Once it's finally done building the project, you should see succeeded up here. And, hopefully, there 110
are no warnings and errors left for you. 111
So now we're done adding Firebase to our iOS app. 112
And if you want, you can get started by reading the Firebase getting started guide for iOS projects. 113
And the thing to note is that Firebase has really good documentation, which as we're getting used to 114
Apple Documentation, you'll notice a world of difference just to how much extra effort they've put in 115
to their documentation. 116
And once you're happy with that, in the next lesson, we're going to get started registering new users 117
to our FlashChat project. 118
So all of that and more, I'll see you on the next lesson.