1
00:00:05,740 --> 00:00:13,180
What's up guys I'm Jacob Blitzer with slopes dot com and in the last the last lesson we finished up

2
00:00:13,180 --> 00:00:16,300
getting our basic designs done.

3
00:00:16,510 --> 00:00:22,450
So in this lesson what we're going to do is we're going to get our begin run b c done.

4
00:00:22,540 --> 00:00:29,710
So we're going to get this map view showing up and also showing our location.

5
00:00:29,710 --> 00:00:31,020
So a lot of a cool.

6
00:00:31,090 --> 00:00:41,560
And then we'll get the start button wired up to go to the the on run Visi and we will also get all the

7
00:00:41,560 --> 00:00:52,330
IAB outlets on the begin run Visi hooked up and a few other things will get our cell location delegate

8
00:00:52,330 --> 00:00:55,020
and all that stuff wired in and work in.

9
00:00:55,020 --> 00:00:56,500
So this will be good.

10
00:00:56,500 --> 00:01:05,230
And before we start though we need to open up our terminal and make sure you guys are at least committing

11
00:01:05,290 --> 00:01:08,470
your changes and keeping track of it with get.

12
00:01:08,470 --> 00:01:16,300
I'm going to make another branch so you guys can go exactly to this branch when you're following along

13
00:01:16,360 --> 00:01:19,960
and get exactly the work up to this lessens point.

14
00:01:19,990 --> 00:01:25,310
So I'm going to do a get check out dash B and this is going to be less than four.

15
00:01:25,970 --> 00:01:26,410
All right.

16
00:01:26,410 --> 00:01:27,120
Great.

17
00:01:27,160 --> 00:01:28,600
And let's get going.

18
00:01:28,600 --> 00:01:35,770
So what do we have to do we have to start hooking up IAB outlets for the run Visi before we can do anything

19
00:01:35,770 --> 00:01:36,190
else.

20
00:01:36,190 --> 00:01:39,580
So how do we do that.

21
00:01:39,590 --> 00:01:44,650
You know we could manually type out the Iby outlets and things but I prefer just doing the will split

22
00:01:44,650 --> 00:01:51,830
view here and here is our begin view lets get this window out of the way.

23
00:01:53,320 --> 00:02:03,270
If I remember how there we go just click this show document outlined down here below your storyboard

24
00:02:04,470 --> 00:02:13,050
and if you click this shella assistant editor if the run VC was selected it should pop up automatically

25
00:02:13,170 --> 00:02:19,530
if not no big deal just click up here go to manual go into your project and you can find the view controller

26
00:02:19,530 --> 00:02:26,370
you want and we want begin run Visi and let's delete this did receive memory Warren in.

27
00:02:26,580 --> 00:02:27,750
We don't need that.

28
00:02:27,750 --> 00:02:32,390
And also this comma the comments are cool.

29
00:02:32,790 --> 00:02:42,660
So first things first let's hook up all of our our outlets.

30
00:02:42,710 --> 00:02:50,090
So if you hold control like let's select our map do here you hold control and drag over here we can

31
00:02:50,090 --> 00:02:54,170
go ahead and call this our map view and it can.

32
00:02:54,230 --> 00:02:57,100
Or hit enter and that's connected.

33
00:02:57,410 --> 00:03:00,280
And now you can click on our.

34
00:03:00,320 --> 00:03:03,720
We actually don't need an IP outlet for the start.

35
00:03:03,730 --> 00:03:08,240
Ron and I will discuss that in a second.

36
00:03:08,240 --> 00:03:12,690
So let's just go ahead and hook up our central location as well.

37
00:03:13,010 --> 00:03:15,920
And we don't need an I.V. for this one either.

38
00:03:15,920 --> 00:03:23,030
Let's just hold control click and drag and underneath the view to load let go and make sure you change

39
00:03:23,030 --> 00:03:34,140
the connection type to action and we will call this location center button pressed.

40
00:03:34,220 --> 00:03:43,100
It's always nice to be as descriptive as you can and this will be the function that's called when you

41
00:03:43,100 --> 00:03:48,660
push that button and that'll be centering on our location in a little bit.

42
00:03:48,680 --> 00:03:52,430
I don't think it'll happen this lesson but that is what it will be for.

43
00:03:52,460 --> 00:04:01,220
And like I said before we're getting yelled at because I hooked up a map view and we don't have map

44
00:04:01,220 --> 00:04:07,760
kit imported So let's go ahead and do import map kit and that should take care of that.

45
00:04:07,810 --> 00:04:09,050
It wants us to

46
00:04:12,720 --> 00:04:14,740
yeah now are good.

47
00:04:14,740 --> 00:04:15,100
All right.

48
00:04:15,130 --> 00:04:21,700
And so I said we don't need an action for this or an IAB outlet because we can actually just click this

49
00:04:22,030 --> 00:04:31,140
and do a controlled drag to this Visi to the current run Visi and let go and just click on Show.

50
00:04:31,510 --> 00:04:35,020
And now that button will go to this Visi And that's exactly what we want.

51
00:04:35,020 --> 00:04:37,480
So we don't need to add any code for that.

52
00:04:37,480 --> 00:04:39,780
So that's pretty nice.

53
00:04:39,790 --> 00:04:42,420
So something I want you guys to think about.

54
00:04:42,460 --> 00:04:53,140
We are using C-L location and like Map kit stuff and both these VCs and we have to you know get user

55
00:04:53,140 --> 00:04:55,960
permission and all that good stuff.

56
00:04:56,200 --> 00:05:03,430
So what I'm going to do is I'm actually going to show you we're going to make another VC that both these

57
00:05:03,430 --> 00:05:04,990
VCs can inherit from.

58
00:05:04,990 --> 00:05:10,840
So we only have to write code once like the authorization code and then we'll also use the

59
00:05:14,450 --> 00:05:22,670
excuse me I forgot the name so I'm going to look we can also use the C-L location manager for both views

60
00:05:22,700 --> 00:05:27,880
and only have one we just have to make sure we assign the delegate to each view when we go to it.

61
00:05:27,920 --> 00:05:30,410
And then we can use the same manager.

62
00:05:30,440 --> 00:05:34,350
And it makes things a lot easier and we don't have to rewrite code.

63
00:05:34,790 --> 00:05:40,710
But before we go any further you do have to ask the user permission to find their location.

64
00:05:40,880 --> 00:05:44,600
So you have to open up the info list over here.

65
00:05:44,630 --> 00:05:53,570
Inside your project and on the bottom here just hit this last arrow and if you start typing privacy

66
00:05:54,880 --> 00:05:56,380
you'll see all these things.

67
00:05:56,380 --> 00:06:04,370
And if you go and find location and then this one location when in use that's the one we want.

68
00:06:04,510 --> 00:06:10,330
And now if you do a location always Apple usually will reject apps for that so you get to keep that

69
00:06:10,330 --> 00:06:12,840
in mind unless you have a really good reason for using it.

70
00:06:13,030 --> 00:06:17,040
But in-use is fine because we're going to be using the app when we're running.

71
00:06:17,560 --> 00:06:23,350
You might run into problems with it going in the background but you can always address those letter.

72
00:06:23,770 --> 00:06:30,160
But for everything we're doing right now when in use is fine and right here in the string here this

73
00:06:30,160 --> 00:06:31,630
is the message that shows up.

74
00:06:31,630 --> 00:06:35,310
So we're going to since we called our app treads I'm going to say

75
00:06:39,210 --> 00:06:47,920
treads needs your location for tracking for tracking your run.

76
00:06:48,480 --> 00:06:53,460
And I think that's good and that will show up in the message when the users prompt for giving their

77
00:06:53,460 --> 00:06:55,050
location.

78
00:06:55,080 --> 00:07:03,960
And so if we go back to our beginning run we see when to actually go ahead and get rid of the assistant.

79
00:07:03,960 --> 00:07:11,990
View there because we have our ibl hooked up we have everything that we need at the moment.

80
00:07:13,980 --> 00:07:18,150
So yeah let's see what should we do right now.

81
00:07:18,150 --> 00:07:24,270
I think what I'm going to do is make that extra VC I said where were going to set up all of our the

82
00:07:24,270 --> 00:07:26,080
C-L location manager stuff.

83
00:07:26,280 --> 00:07:34,150
So on the controller folder go ahead and right click that and hit new file and this is going to be Iowa

84
00:07:34,250 --> 00:07:45,310
cocoa touch class and we are going to call this location Visi and make sure it's you I view controller

85
00:07:45,430 --> 00:07:46,230
that's important.

86
00:07:47,350 --> 00:07:48,610
And that looks good.

87
00:07:48,610 --> 00:07:53,430
Create and let's delete all this stuff here.

88
00:07:53,530 --> 00:07:55,590
And we don't need these comments.

89
00:07:55,810 --> 00:08:02,170
All right so what we need in our location Visi we're going to need to import our map kit again

90
00:08:05,810 --> 00:08:16,510
right map kit and we're also going to have to inherit from our M-K map view delegates right.

91
00:08:16,520 --> 00:08:27,950
So when we do that that will basically allow us to set the C-L location manager and we can also when

92
00:08:27,950 --> 00:08:36,410
we inherit when our other VCs inherit from inherit from this they won't have to inherit from either

93
00:08:36,410 --> 00:08:38,920
of these two classes so it's really nice.

94
00:08:38,930 --> 00:08:47,480
So the first things first we have to create our RCL location manager so let's call it var manager and

95
00:08:47,480 --> 00:08:51,800
it's going to be of type C-L location manager.

96
00:08:52,820 --> 00:08:57,530
And this is optional because we don't actually know if this is assigned so we don't want to just force

97
00:08:57,530 --> 00:08:58,870
on wrap things.

98
00:08:59,120 --> 00:09:05,790
And then in the view load We're going to say Manager equals equals.

99
00:09:05,940 --> 00:09:10,280
See location manager and then opening and closing parentheses.

100
00:09:10,310 --> 00:09:18,620
And that sets our manager to a new instance of a location manager and a couple of things we're going

101
00:09:18,620 --> 00:09:25,740
to need to do is we need to know the the accuracy and the activity type.

102
00:09:26,510 --> 00:09:33,010
And these are just you can find these in Apple documents if you need to look them up.

103
00:09:33,080 --> 00:09:39,260
So we're going to go ahead and say Manager dot desired accuracy and this is going to hit hit Eagle and

104
00:09:39,260 --> 00:09:48,220
you have to do a case see look I'm sorry Casey location accuracy best.

105
00:09:48,230 --> 00:09:55,190
So we want it the best like we're not driving a car we're just you know we're running we're moving not

106
00:09:55,190 --> 00:10:01,340
as you know not as far as like a car GPS would be so we want as accurate as possible because we're only

107
00:10:01,350 --> 00:10:11,960
moving you know like I don't know four or five miles an hour not very fast.

108
00:10:12,180 --> 00:10:15,520
So once we do that we also want to set the activity time.

109
00:10:15,570 --> 00:10:21,960
And we can do that by manager and then activity type equals and then you just do a dot and it will find

110
00:10:21,960 --> 00:10:28,470
all the options for us so if you if it was an auto a motive or if it was an automotive app we could

111
00:10:28,470 --> 00:10:33,930
do automotive navigation or whatever you want but we want to set this to fitness and that'll make it

112
00:10:33,930 --> 00:10:36,050
a little more accurate for us.

113
00:10:37,770 --> 00:10:46,350
And then one function that we need that we're going to share between our begin run Visi and our current

114
00:10:46,350 --> 00:10:50,910
run Visi is we have to check the location off status.

115
00:10:51,090 --> 00:10:58,330
So we're just going to call this function check location status.

116
00:10:59,310 --> 00:11:00,050
OK.

117
00:11:00,060 --> 00:11:09,620
And then basically we're just going to check to see what the status is so if C-L location manager dot

118
00:11:09,680 --> 00:11:16,640
authorization status does not equal dot authorize when in use.

119
00:11:16,640 --> 00:11:21,890
So that means the user has an authorized use for us to know their location.

120
00:11:21,890 --> 00:11:32,060
Then we need to call the manager that we established and say request when in use authorization.

121
00:11:32,370 --> 00:11:33,460
OK.

122
00:11:33,780 --> 00:11:35,360
So when that is done.

123
00:11:35,370 --> 00:11:43,410
So basically if it's if the status isn't authorized the phone or the user will be prompted for authorization

124
00:11:44,220 --> 00:11:47,820
and that's all we need in this location visi.

125
00:11:47,880 --> 00:11:53,360
And I'm just going to drag this location b.s. to the top because it's going to be shared.

126
00:11:53,490 --> 00:12:02,690
And now if we go back to our begin run Visi always do to have all that information from this Visi is

127
00:12:02,760 --> 00:12:07,920
let's get rid of this you view controller we don't inherit it anymore because location Visi does and

128
00:12:07,920 --> 00:12:10,940
we just have to inherit from location visi.

129
00:12:11,080 --> 00:12:13,040
It's pretty cool.

130
00:12:14,010 --> 00:12:20,910
And so once we do that the your view is going to load and we need to check authorization status right

131
00:12:20,910 --> 00:12:21,270
away.

132
00:12:21,270 --> 00:12:31,040
So let's go ahead and say check location off status and that since we're inheriting we have this full

133
00:12:31,040 --> 00:12:34,640
capability to access that function which is pretty cool.

134
00:12:34,820 --> 00:12:41,710
And then we also need to now set our map view delegate and that is that delegate.

135
00:12:41,750 --> 00:12:43,850
And we want to just set that to sell.

136
00:12:43,910 --> 00:12:46,510
We're only using the map view on this one.

137
00:12:46,730 --> 00:12:48,700
So that's pretty easy.

138
00:12:48,950 --> 00:12:51,790
And I think that's good for now.

139
00:12:51,800 --> 00:12:57,680
But now we also have to make sure the manager doesn't get a set and we don't want that view did load

140
00:12:57,710 --> 00:13:03,770
because once this views loaded if we go to the current run we see and come back there's a good chance

141
00:13:03,770 --> 00:13:04,760
is still loaded.

142
00:13:04,760 --> 00:13:11,630
So you did load will not be called and we have to make sure the delegate gets set in both current run

143
00:13:11,630 --> 00:13:13,970
Visi and begin run visi.

144
00:13:14,000 --> 00:13:17,090
So we have to set that delegate.

145
00:13:17,090 --> 00:13:25,400
And our view will appear so if we just side view will appear perfect and we can just go ahead and call

146
00:13:25,400 --> 00:13:31,580
our manager which we have access to because we inherited from location VC and just to delegate equal

147
00:13:31,580 --> 00:13:32,750
self.

148
00:13:32,750 --> 00:13:40,360
And now the delegate for C-L location is set to this visi.

149
00:13:40,480 --> 00:13:41,750
So that's pretty cool.

150
00:13:41,800 --> 00:13:56,150
And now we can also say a manager dot start monitoring location start monitoring now start up date and

151
00:13:56,300 --> 00:13:58,730
location.

152
00:13:58,760 --> 00:13:59,130
All right.

153
00:13:59,130 --> 00:14:00,070
Cool.

154
00:14:00,480 --> 00:14:03,040
Oh you know what this needs to be.

155
00:14:03,260 --> 00:14:04,540
You will appear

156
00:14:10,420 --> 00:14:14,460
want us to see.

157
00:14:14,530 --> 00:14:16,060
I mean we can force

158
00:14:22,110 --> 00:14:22,740
OK.

159
00:14:22,780 --> 00:14:28,690
So we unwrapped it as a location manager delegate which is fine.

160
00:14:28,720 --> 00:14:30,280
This all worked just great.

161
00:14:30,490 --> 00:14:34,550
And in our we also want to do of you did disappear.

162
00:14:34,570 --> 00:14:42,630
You did disappear and we want to make sure we stop updating location because we're going to be reassigning

163
00:14:42,630 --> 00:14:50,500
this delegate when we go to the other VCs So we want to just say stop monitoring location.

164
00:14:51,000 --> 00:14:51,490
OK.

165
00:14:52,350 --> 00:14:53,900
Cool.

166
00:14:53,910 --> 00:15:01,290
All right so with that being done we should be able to run this and just at least see the map so let's

167
00:15:01,290 --> 00:15:02,400
go ahead and run this

168
00:15:10,490 --> 00:15:18,590
whoas superzoom then I'm just going to like 50 percent that an awesome so our check authorization works

169
00:15:18,590 --> 00:15:26,250
we're going to click allow And now we'll see if a dot shows up should show up somewhere.

170
00:15:26,250 --> 00:15:35,520
Let me see if our Loek go to debug location and let's go to the Apple OK.

171
00:15:35,520 --> 00:15:42,780
Well our map showing and we probably just have to add a few more things like we have to set.

172
00:15:43,020 --> 00:15:46,260
Show user location and also enable tracking.

173
00:15:46,260 --> 00:15:51,560
But we're getting there things are and our start run button should take us all the VC suite.

174
00:15:51,600 --> 00:15:55,110
So our other VC works but obviously we can't get out of it.

175
00:15:55,110 --> 00:16:01,560
So let's go ahead and stop this and let's finish making things work.

176
00:16:01,650 --> 00:16:11,400
So we need to inherit or we need to extend this class and we also have to have it inherit from C-L location

177
00:16:11,400 --> 00:16:12,380
manager or delegate.

178
00:16:12,420 --> 00:16:20,340
OK so if we do an extension down here extension and then this is called the begin run Visi and it needs

179
00:16:20,340 --> 00:16:23,820
to inherit from C-L location manager.

180
00:16:26,410 --> 00:16:28,000
DELEGATE.

181
00:16:28,930 --> 00:16:35,220
And the reason we're doing this is because we need location manager and like we need to show the user

182
00:16:35,230 --> 00:16:42,550
location on the map view only on this PC because the other VC doesn't even have a map view so it doesn't

183
00:16:42,550 --> 00:16:43,670
matter.

184
00:16:43,690 --> 00:16:50,170
And now since we inherited the C-L location manager We're going to be able to delete this so let's delete

185
00:16:50,170 --> 00:16:50,520
that.

186
00:16:50,530 --> 00:16:53,880
We don't have to cast it as anything.

187
00:16:53,920 --> 00:16:56,970
And it just it knows what it's supposed to be now.

188
00:16:57,190 --> 00:16:59,240
So that's cool.

189
00:16:59,320 --> 00:17:04,300
So let's go ahead and do a function.

190
00:17:04,300 --> 00:17:13,060
Location Manager and we need did change authorization status.

191
00:17:13,060 --> 00:17:15,930
So where would that change

192
00:17:18,540 --> 00:17:21,160
it did fail.

193
00:17:21,750 --> 00:17:24,110
There's got to be a better way to find this.

194
00:17:24,110 --> 00:17:29,810
One second guys did change

195
00:17:33,480 --> 00:17:39,780
did change authorization there go so go ahead and when you see location manager did change authorization

196
00:17:39,990 --> 00:17:41,080
hit enter.

197
00:17:41,430 --> 00:17:48,090
And in this function we need to just check to make sure our authorization is still set.

198
00:17:48,120 --> 00:17:51,720
So it is passing in a status.

199
00:17:51,950 --> 00:18:01,800
And let's just go ahead and say if status and if that is equal to authorization women use that's good.

200
00:18:02,030 --> 00:18:12,580
And if that's true we want to check location status again just in case you know something.

201
00:18:12,590 --> 00:18:18,230
We want to just always make sure we're authorized to have access and that will actually re-initialize

202
00:18:18,290 --> 00:18:19,530
a lot of things here.

203
00:18:20,680 --> 00:18:24,110
So if we just check our status again that's fine.

204
00:18:24,120 --> 00:18:30,510
And then we want to make our map view show user location you know we need to set.

205
00:18:30,520 --> 00:18:31,980
That's true.

206
00:18:32,590 --> 00:18:33,190
OK.

207
00:18:33,460 --> 00:18:40,350
And then we also need our map view that user tracking mode equals.

208
00:18:40,360 --> 00:18:45,690
And then you can just do a period dot follows and you can do numerous other things.

209
00:18:45,700 --> 00:18:53,410
But we wanted to follow our DOT and those are the only two things we probably have to do to get our

210
00:18:53,410 --> 00:18:55,900
data showing up so let's go ahead and run this again.

211
00:18:59,570 --> 00:19:01,050
And there we go.

212
00:19:01,370 --> 00:19:05,810
And it even zoomed in on us without setting a radius.

213
00:19:05,870 --> 00:19:08,510
So that's pretty cool.

214
00:19:08,510 --> 00:19:19,750
I think we can call this video done and I think in the next video we should probably work on.

215
00:19:20,120 --> 00:19:23,060
Let's see what should we do.

216
00:19:24,470 --> 00:19:32,570
I think we should move on to the current run and what we'll do is we'll get our slider button all hooked

217
00:19:32,570 --> 00:19:33,110
up.

218
00:19:33,110 --> 00:19:41,430
So if we enter this we see we can at least and the run and get back to the other visi.

219
00:19:41,480 --> 00:19:45,600
So in the next video you guys should try to do this.

220
00:19:46,220 --> 00:19:52,460
We're basically animating the UI image view here and allowing a slight gesture to move it.

221
00:19:52,610 --> 00:19:59,820
And when it hits a certain location it can call an action and it will return.

222
00:19:59,870 --> 00:20:02,140
It will exit or dismiss this VC.

223
00:20:02,210 --> 00:20:04,010
So you guys should try to do that.

224
00:20:04,010 --> 00:20:06,310
It's OK if you can't.

225
00:20:06,540 --> 00:20:11,810
This is a pretty cool feature and it can be kind of complicated to understand at first but before we

226
00:20:11,810 --> 00:20:19,620
end let's just make sure we pull up our terminal and do a get ad period and then a dash and.

227
00:20:19,910 --> 00:20:28,070
And let's see we got our map view and Loek shared location.

228
00:20:28,380 --> 00:20:36,160
And I just hit enter and we are good to go and I will see you guys in the next lesson.
