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