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