1
00:00:07,670 --> 00:00:12,250
Hey everybody this is Caleb with slopes and in this video it's going to be a shorter one we're going

2
00:00:12,250 --> 00:00:16,150
to basically enable our camera to utilize the flash.

3
00:00:16,150 --> 00:00:20,980
We can set it to be automatic but I think it's cool to give the user the ability to control whether

4
00:00:20,980 --> 00:00:22,810
or not their flash is on or off.

5
00:00:22,810 --> 00:00:23,820
So we're going to do that.

6
00:00:23,920 --> 00:00:25,110
It's very easy.

7
00:00:25,120 --> 00:00:29,630
Let's go ahead and pull open that X code project and let's make it happen right now.

8
00:00:29,770 --> 00:00:33,880
So to begin we actually need to think about the flash option.

9
00:00:33,880 --> 00:00:36,480
We either can have the flash on or off.

10
00:00:36,490 --> 00:00:43,660
And to control that we're going to use an enum to just kind of control the state of the flash the flash

11
00:00:43,670 --> 00:00:44,310
light.

12
00:00:44,470 --> 00:00:46,360
So an ENM can be used for this.

13
00:00:46,360 --> 00:00:56,320
We can go ahead and type Inam flash state and we can give it to cases either off or on can we can use

14
00:00:56,320 --> 00:01:05,710
this ENM to basically save the state of the honor off light and then later we can tell the camera that

15
00:01:05,710 --> 00:01:09,500
we want it to be off or on based on what the user sets with the buttons.

16
00:01:09,650 --> 00:01:11,070
OK very cool.

17
00:01:11,110 --> 00:01:16,900
And actually before we even go further than this we're going to need to create a default state.

18
00:01:16,920 --> 00:01:21,640
So when the app opens we're going to set it to be off by default because I think most people would probably

19
00:01:21,640 --> 00:01:26,290
want it to be off unless they want it to be on for the most part.

20
00:01:26,290 --> 00:01:32,870
So to do that go ahead and type var flash control state.

21
00:01:33,040 --> 00:01:37,820
That's of course going to be of type flash state and we're going to actually just do this.

22
00:01:38,020 --> 00:01:40,670
We're going to set it to be off by default.

23
00:01:40,720 --> 00:01:46,540
Now when this variable is utilized when we actually instantiated it's going to get set to be off just

24
00:01:46,540 --> 00:01:47,390
from the get go.

25
00:01:47,440 --> 00:01:48,410
OK that's very cool.

26
00:01:48,430 --> 00:01:50,020
Very easy way to do it.

27
00:01:50,200 --> 00:01:53,530
And you know while I'm here I'm going to get rid of that comment.

28
00:01:53,590 --> 00:01:54,650
Don't need it.

29
00:01:55,150 --> 00:02:02,230
And now what we're going to do is we're going to utilize that ENM to go ahead and set up our settings

30
00:02:02,230 --> 00:02:08,160
for the flash and the way we do that is where we capture our photo.

31
00:02:08,490 --> 00:02:10,110
It did tap camera view.

32
00:02:10,270 --> 00:02:10,770
OK.

33
00:02:10,990 --> 00:02:12,520
So we have capture photo here.

34
00:02:12,520 --> 00:02:16,630
And the cool thing is one of the settings is the flash mode.

35
00:02:16,660 --> 00:02:22,690
So we're going to use our our variable up here flash control state which of course is set off at the

36
00:02:22,690 --> 00:02:23,770
beginning.

37
00:02:23,770 --> 00:02:31,570
We're going to go ahead and we're going to type if Flash control state is equal to off.

38
00:02:31,900 --> 00:02:42,640
OK so when we open the app if it's equal to off we're going to call settings flash mode equals off else

39
00:02:43,480 --> 00:02:47,050
telling you guys this is easy stuff else settings.

40
00:02:47,080 --> 00:02:49,260
Flash mode equals on.

41
00:02:49,510 --> 00:02:54,310
And actually you know what you probably noticed there is an auto setting which automatically monitors

42
00:02:54,310 --> 00:03:00,310
the light around you but the user wants to have control ultimately over the flash mode whether it's

43
00:03:00,340 --> 00:03:01,510
on or off.

44
00:03:01,510 --> 00:03:01,990
OK.

45
00:03:02,140 --> 00:03:04,710
So that's that if it's off the flash mode will be off.

46
00:03:04,720 --> 00:03:07,180
If it's on the flash motor will be on.

47
00:03:07,180 --> 00:03:08,090
All right.

48
00:03:08,230 --> 00:03:09,380
Super easy.

49
00:03:09,520 --> 00:03:11,460
Now that's how we're going to control it.

50
00:03:11,470 --> 00:03:16,360
But the thing we need to think about is how will we change the flash control state.

51
00:03:16,360 --> 00:03:18,040
And we're going to use.

52
00:03:18,070 --> 00:03:20,960
Let me show you the example here where is it.

53
00:03:21,180 --> 00:03:24,320
We're going to use the flash button to change the state if.

54
00:03:24,350 --> 00:03:31,000
If it's off and we tap the button it should change to say on and we should change the flash control

55
00:03:31,000 --> 00:03:32,900
state to be on as well.

56
00:03:32,980 --> 00:03:36,790
So to do that we're going to use an IB action as you may have suspected.

57
00:03:36,850 --> 00:03:41,650
So to do that go ahead and go to main storyboard let it load.

58
00:03:41,650 --> 00:03:42,600
There we go.

59
00:03:42,850 --> 00:03:50,050
And go ahead and tap on the little assistant editor and it looks like we're already properly in our

60
00:03:50,290 --> 00:03:51,850
control or that's great.

61
00:03:51,850 --> 00:03:53,920
So scroll down to the bottom.

62
00:03:54,070 --> 00:04:00,380
Iby actions are usually put at the bottom of a code file just by convention and go and right click and

63
00:04:00,380 --> 00:04:04,980
then drag and we're going to use this to create an IB action.

64
00:04:04,990 --> 00:04:06,640
So go ahead and type sorry.

65
00:04:06,850 --> 00:04:14,950
Choose action then type flash button was pressed to basically describe what happens when that IAB action

66
00:04:14,950 --> 00:04:15,480
is used.

67
00:04:15,550 --> 00:04:19,400
We're pushing a button to trigger that action.

68
00:04:19,420 --> 00:04:25,540
Now what we're going to do is we're basically going to use a switch to flip between the two different

69
00:04:25,810 --> 00:04:26,770
states.

70
00:04:26,770 --> 00:04:33,520
So go ahead and type switch and we're going to create a switch of flash control state and there are

71
00:04:33,520 --> 00:04:43,360
two cases of course that we can switch between one is case off and the other one is case on.

72
00:04:43,360 --> 00:04:44,560
Simple as that.

73
00:04:44,560 --> 00:04:51,070
Now if the case are sorry if the flash control state is off and we tap the button we should change the

74
00:04:51,070 --> 00:04:58,900
button title to say on OK if it's off and we tap it it should say on if it's on and we tap it it should

75
00:04:58,900 --> 00:04:59,650
say off.

76
00:04:59,650 --> 00:05:05,570
So to do that go ahead and type flash control or flash button I suppose.

77
00:05:05,800 --> 00:05:10,210
And to change the title you need to do set title.

78
00:05:10,210 --> 00:05:17,920
Now of course the title string will say whoops we'll say flash on in caps and the UI control state is

79
00:05:17,920 --> 00:05:19,820
actually just normal.

80
00:05:19,900 --> 00:05:23,110
That way we can actually set it when we tap the button.

81
00:05:23,110 --> 00:05:29,050
And after that if if the flash control state is off we tap the button to make it say on.

82
00:05:29,050 --> 00:05:34,900
We should also change the flash control state to be on because then the flash should be on.

83
00:05:34,960 --> 00:05:35,320
OK.

84
00:05:35,320 --> 00:05:36,420
Simple as that.

85
00:05:36,520 --> 00:05:40,900
And you're probably guessing this already but basically we're going to do the exact opposite of this

86
00:05:41,110 --> 00:05:47,240
for the other case so I'm actually going to copy and paste it because it's very very very little code.

87
00:05:47,290 --> 00:05:52,600
I'm going to change the title to say flash off and the control state will also be off.

88
00:05:52,810 --> 00:05:56,340
Now believe it or not this is all we needed to do to set up our flash.

89
00:05:56,350 --> 00:05:58,770
But there's one thing that's just been bugging me.

90
00:05:58,990 --> 00:06:03,550
This green view I want to change it to be white again because it shouldn't be shouldn't be green just

91
00:06:03,550 --> 00:06:05,020
doesn't look right.

92
00:06:05,020 --> 00:06:09,090
Keiko hadn't changed that to white and build and run this out.

93
00:06:09,100 --> 00:06:11,170
Let's go see how we did going to close.

94
00:06:11,170 --> 00:06:14,140
My assistant editor there.

95
00:06:14,530 --> 00:06:16,260
It should build and run.

96
00:06:16,390 --> 00:06:17,250
We should see it.

97
00:06:17,260 --> 00:06:19,270
And we should be able to turn the flash off.

98
00:06:19,420 --> 00:06:19,950
OK.

99
00:06:20,140 --> 00:06:21,380
Let's try to take a picture here.

100
00:06:22,600 --> 00:06:23,110
OK good.

101
00:06:23,110 --> 00:06:23,840
In a flash.

102
00:06:23,890 --> 00:06:25,670
Let's tap the button.

103
00:06:25,750 --> 00:06:28,720
The label changed and let's see you want to take a picture now.

104
00:06:29,080 --> 00:06:31,800
Hey there's the flash.

105
00:06:31,810 --> 00:06:32,890
It works.

106
00:06:33,070 --> 00:06:33,790
That's so cool.

107
00:06:33,790 --> 00:06:35,030
So let's try it again.

108
00:06:35,390 --> 00:06:36,340
Yep we've got a flash.

109
00:06:36,340 --> 00:06:37,450
Let's turn it off.

110
00:06:38,360 --> 00:06:46,160
Know flash see that super super cool awesome job guys that's all we needed to do to integrate the flash

111
00:06:46,550 --> 00:06:52,220
in the next video we're actually going to go ahead and we're going to set up Avies speech synthesizer

112
00:06:52,430 --> 00:06:57,650
so that we can speak what is happening what are what our phone is seeing right now seeing or remote

113
00:06:57,650 --> 00:06:58,170
control.

114
00:06:58,190 --> 00:07:03,910
We're going to set it up so that it says I think this is a remote control and I'm 99 percent sure if

115
00:07:03,920 --> 00:07:06,160
it's not sure it's going to say this message.

116
00:07:06,170 --> 00:07:07,220
I'm not sure what this is.

117
00:07:07,220 --> 00:07:08,350
Please try again.

118
00:07:08,450 --> 00:07:09,670
Simple as that.

119
00:07:09,830 --> 00:07:11,240
So we'll see in the next video.

120
00:07:11,240 --> 00:07:12,650
Amazing work with this one.

121
00:07:12,650 --> 00:07:14,630
This is Caleb with Dev slopes dot com.
