1
00:00:06,530 --> 00:00:13,790
And now what we can do is we can go ahead and modify our IP service to account for this one as well.

2
00:00:13,980 --> 00:00:20,310
So go ahead and head into IAP service and this is where we need to modify because right now we're only

3
00:00:20,310 --> 00:00:24,090
passing in one one set.

4
00:00:24,150 --> 00:00:25,700
Right one IAP.

5
00:00:25,800 --> 00:00:29,720
Now what we're going to do is we're going to go ahead and actually create an array and then we're going

6
00:00:29,710 --> 00:00:31,970
to for loop through them and insert them one by one.

7
00:00:31,980 --> 00:00:39,600
So go ahead and type let product IDs equals an array containing IAP.

8
00:00:39,650 --> 00:00:42,330
Neil ID as well as IAP.

9
00:00:42,360 --> 00:00:44,900
Hide ads Id get rid of that.

10
00:00:44,910 --> 00:00:53,150
And now what we can do is we can say for ID in product IDs we can go ahead and call product IDs insert

11
00:00:53,220 --> 00:00:55,480
and we can insert the ID.

12
00:00:55,680 --> 00:01:00,190
So by the end we have a set with two items one is IAP Mileti.

13
00:01:00,210 --> 00:01:02,280
The other one is hide adds ID.

14
00:01:02,550 --> 00:01:04,090
OK super simple.

15
00:01:04,320 --> 00:01:08,640
Not too bad although look at that its giving us some trouble.

16
00:01:08,800 --> 00:01:14,410
Its saying cannot use on non mutable to let constant What are you talking about.

17
00:01:15,280 --> 00:01:16,760
Product IDs is a very.

18
00:01:16,960 --> 00:01:17,720
Oh this one.

19
00:01:17,820 --> 00:01:18,050
OK.

20
00:01:18,070 --> 00:01:26,170
So let's just let's change this to just be IDs then and just say for ID in IDs that way we're actually

21
00:01:26,170 --> 00:01:28,790
referring to the proper set.

22
00:01:28,790 --> 00:01:29,840
Very cool.

23
00:01:29,950 --> 00:01:34,540
So now when we load our app we have access to hide ads ID.

24
00:01:34,610 --> 00:01:35,860
OK super cool.

25
00:01:36,180 --> 00:01:38,620
And thanks to what we've already done.

26
00:01:38,620 --> 00:01:46,420
Believe it or not we can call our purchase function attempt to purchase for item with we can pass in

27
00:01:46,420 --> 00:01:51,340
the Product ID and we can attempt to make that purchase which is really cool.

28
00:01:51,370 --> 00:01:53,290
Let's go ahead and let's try that.

29
00:01:53,290 --> 00:02:02,160
So on detail we see when the hied ads button is pressed we just need to call IAP service instance attempt

30
00:02:02,270 --> 00:02:07,470
to purchase for item with product index hide ads and that's what we're going to pass in.

31
00:02:07,600 --> 00:02:12,880
So that way we can attempt to purchase for hiding ads and I don't know about you but I really want to

32
00:02:12,880 --> 00:02:13,740
see if it works.

33
00:02:13,810 --> 00:02:20,840
Let's go ahead and build and run let's test to see if we can successfully queue our hiding ads in at

34
00:02:20,850 --> 00:02:21,740
purchase.

35
00:02:21,880 --> 00:02:23,390
Let's give it a test here we go.

36
00:02:23,680 --> 00:02:30,830
So pull open the simulator here and let's go ahead and select an item tap hide ads for 99 cents.

37
00:02:30,880 --> 00:02:32,480
OK it's going to ask us to sign in.

38
00:02:32,590 --> 00:02:34,180
Fine.

39
00:02:34,210 --> 00:02:36,040
Test test one two three.

40
00:02:36,370 --> 00:02:38,060
Whoops only one exclamation mark.

41
00:02:38,060 --> 00:02:41,890
Press OK and we should get a Q here.

42
00:02:41,890 --> 00:02:44,470
Do you want to buy one meal for 999.

43
00:02:44,890 --> 00:02:48,100
That's not the right purchase press cancel.

44
00:02:48,100 --> 00:02:53,700
Now watch what happens when I tap by this item it says Do you want to buy one hide ads for 99 cents.

45
00:02:53,710 --> 00:02:55,450
Why is it flipped.

46
00:02:55,450 --> 00:03:03,920
The reason for that is because we set a specific product ID K meal being 0 and hide ads being one.

47
00:03:03,970 --> 00:03:08,680
But when we create this set we pass in IDS.

48
00:03:08,740 --> 00:03:14,800
We pass in the ID then we pass in Hyde ad and it ends up being reversed.

49
00:03:14,800 --> 00:03:20,350
So what we can do is we can go ahead and just pass that one in first and then it will be properly set

50
00:03:20,350 --> 00:03:27,530
at the bottom of the set because insert basically inserts the given element at the top.

51
00:03:27,760 --> 00:03:28,250
OK.

52
00:03:28,450 --> 00:03:30,760
So when you insert a new element it puts it at the top.

53
00:03:30,760 --> 00:03:34,740
So we need to put the meal at the top and hide ads idea at the bottom.

54
00:03:34,810 --> 00:03:36,520
OK so we've got to go in reverse order.

55
00:03:36,700 --> 00:03:37,630
Let's try that again.

56
00:03:37,630 --> 00:03:43,150
We're going to build and run and we'll see if reversing that properly allows us to choose the purchase

57
00:03:43,180 --> 00:03:44,100
we want.

58
00:03:44,110 --> 00:03:45,280
Let's take a look.

59
00:03:45,310 --> 00:03:51,110
Select Top buy or hide ads for 99 cents and we get a crash.

60
00:03:51,140 --> 00:03:53,740
Interesting index out of range.

61
00:03:53,740 --> 00:03:55,320
Now why would that be.

62
00:03:55,360 --> 00:03:56,610
This is another error.

63
00:03:56,950 --> 00:03:59,620
Do you notice IAP products loaded.

64
00:03:59,620 --> 00:04:00,430
I don't.

65
00:04:00,430 --> 00:04:03,660
That's because we never loaded them than we went in too fast.

66
00:04:03,670 --> 00:04:10,690
So later on we can set up something where everything is locked until that protocol is called or I guess

67
00:04:10,690 --> 00:04:15,160
that delegate method here is called We can set it to lock everything until this is called.

68
00:04:15,190 --> 00:04:16,770
So go ahead and build and run again.

69
00:04:16,780 --> 00:04:21,210
And we're going to wait this time until our IAAPA products are loaded.

70
00:04:21,310 --> 00:04:21,760
OK.

71
00:04:21,880 --> 00:04:27,520
So now they are you can see that here now that they're loaded we can go in we can tap one and it says

72
00:04:27,520 --> 00:04:29,680
Do you want to buy one meal for 999.

73
00:04:29,680 --> 00:04:30,700
It still says that.

74
00:04:30,790 --> 00:04:38,440
Interesting and it still says Would you like to buy that item so it looks like arranging the order is

75
00:04:38,440 --> 00:04:39,860
not having an impact.

76
00:04:39,990 --> 00:04:43,150
What does have an impact though is changing the index.

77
00:04:43,150 --> 00:04:48,450
So let's go ahead change this to one to zero and I like to put this this way.

78
00:04:48,520 --> 00:04:54,080
Like so hide ads and meal and let's go read up a little more on why this is happening.

79
00:04:54,190 --> 00:04:56,130
Inserts the given element into the set.

80
00:04:56,140 --> 00:05:00,820
If it's not already present if an element equal to new member is already contained this method has no

81
00:05:00,820 --> 00:05:01,420
effect.

82
00:05:01,630 --> 00:05:03,400
So it only adds new elements.

83
00:05:03,580 --> 00:05:04,150
And let's see.

84
00:05:04,150 --> 00:05:12,550
So they add in Wednesday Friday and then they insert Monday so it prints Monday because that's the new

85
00:05:12,550 --> 00:05:13,100
one.

86
00:05:13,270 --> 00:05:20,140
Then they print the whole set and it prints Friday Wednesday Monday so it looks like the last element

87
00:05:20,830 --> 00:05:22,310
gets printed first.

88
00:05:22,330 --> 00:05:26,250
The second element or the first element it's printed second and the new element goes at the very end.

89
00:05:26,260 --> 00:05:27,550
That's interesting.

90
00:05:27,550 --> 00:05:28,380
So if we insert.

91
00:05:28,390 --> 00:05:31,300
Friday it's going to go ahead and put it at the front.

92
00:05:31,300 --> 00:05:38,530
So it looks like whenever something is inserted and it's not new it goes to the front and the other

93
00:05:38,530 --> 00:05:39,220
one goes to the back.

94
00:05:39,220 --> 00:05:39,430
OK.

95
00:05:39,430 --> 00:05:39,850
Interesting.

96
00:05:39,850 --> 00:05:44,620
So it looks like this doesn't matter because these are both where we're passing them and at the same

97
00:05:44,620 --> 00:05:45,220
time.

98
00:05:45,460 --> 00:05:50,200
But it appears that they are going in this way so we're going to reverse the order of our index and

99
00:05:50,200 --> 00:05:53,440
build and run again to see if this helps our problem.

100
00:05:53,470 --> 00:06:01,950
So let's do that again pull up in our sim and let's see how we did Kate tap on salmon tap on hied ads

101
00:06:01,950 --> 00:06:03,400
for 99 cents.

102
00:06:03,420 --> 00:06:05,610
Do you want to buy hied ads for 99 cents.

103
00:06:05,610 --> 00:06:06,390
Very cool.

104
00:06:06,390 --> 00:06:09,080
Now obviously you're probably thinking this is not the most elegant way of doing it.

105
00:06:09,090 --> 00:06:09,530
You're right.

106
00:06:09,570 --> 00:06:12,060
But there are better ways of doing this.

107
00:06:12,060 --> 00:06:15,990
This is just the way that I found that worked pretty well for a simple case like this where we don't

108
00:06:15,990 --> 00:06:18,150
have a ton of complex in-app purchases.

109
00:06:18,300 --> 00:06:21,510
You would want to think of something a little more specific and less error prone.

110
00:06:21,630 --> 00:06:25,860
If you are going to be doing this for very complex apps but this will work fine just for a simple app.

111
00:06:26,100 --> 00:06:28,170
So let's see what happens when we pushed by

112
00:06:31,000 --> 00:06:32,590
your purchase was successful.

113
00:06:32,620 --> 00:06:38,500
We successfully purchased hide ads and that is a non consumable purchase so watch what happens if I

114
00:06:38,500 --> 00:06:41,980
tap it again says Do you want to buy it for 99 cents.

115
00:06:41,980 --> 00:06:43,210
Tapped by.

116
00:06:43,750 --> 00:06:45,760
And it's going to say you've already purchased this.

117
00:06:45,760 --> 00:06:47,890
Would you like to get it again for free tap.

118
00:06:47,910 --> 00:06:48,870
OK.

119
00:06:49,390 --> 00:06:50,770
Your purchase was successful.

120
00:06:50,770 --> 00:06:52,030
Very very cool.

121
00:06:52,030 --> 00:06:55,540
So that is what's going to present to you when you do that.

122
00:06:55,540 --> 00:06:59,850
If you've already bought it it knows and all it needs to do is just say hey you already got this.

123
00:06:59,850 --> 00:07:00,760
Buy it for FREE.

124
00:07:00,760 --> 00:07:01,690
Boom.

125
00:07:01,810 --> 00:07:03,020
Super awesome.

126
00:07:03,220 --> 00:07:06,620
Now we're going to do is we're going to set up something really simple.

127
00:07:06,700 --> 00:07:15,010
It's basically a way for us to determine whether the ad and the button shows or not and so to do that

128
00:07:15,100 --> 00:07:20,050
what we're going to do is we're going to use user defaults K and we're going to use user defaults to

129
00:07:20,080 --> 00:07:28,660
essentially save a Boolean for hidden or not hidden depending on whether or not the purchase has been

130
00:07:28,660 --> 00:07:30,340
made for a non consumable.

131
00:07:30,340 --> 00:07:33,160
So to do this we're going to go to IAP service.

132
00:07:33,160 --> 00:07:42,310
Scroll to the top and we're going to make a property right here called var non consumable purchase was

133
00:07:42,310 --> 00:07:48,340
made and we're going to set it to be equal to user defaults dot standard.

134
00:07:48,370 --> 00:07:52,960
OK just to access the standard user default and then call that bull for key.

135
00:07:53,020 --> 00:07:55,700
So we're making a boolean and we're saving it with a key.

136
00:07:55,720 --> 00:07:59,020
And you know what I'm going to use its name as the key.

137
00:07:59,050 --> 00:07:59,700
OK.

138
00:08:00,100 --> 00:08:06,970
And basically this key is going to be used to access this boolean value and we can save it or set it

139
00:08:08,020 --> 00:08:14,170
and then it'll save permanently into user defaults and we can use this to know whether or not a certain

140
00:08:14,230 --> 00:08:16,470
non consumable purchase has been made or not.

141
00:08:16,480 --> 00:08:16,740
OK.

142
00:08:16,750 --> 00:08:18,060
Very cool.

143
00:08:18,070 --> 00:08:24,970
So what we're going to do now is we need a way to differentiate between a purchase of a meal which is

144
00:08:24,970 --> 00:08:29,090
consumable and a purchase of hide ads which is non consumable.

145
00:08:29,170 --> 00:08:34,210
So we're actually going to go ahead and make a function called comp. And then we'll pass and the transaction

146
00:08:34,210 --> 00:08:40,070
will determine whether it comes from the meal or the purchase for hiding ads.

147
00:08:40,180 --> 00:08:45,160
And then we can either save the boolean value or not because buying food shouldn't have any impact on

148
00:08:45,160 --> 00:08:45,870
the ads.

149
00:08:46,090 --> 00:08:54,430
So let's actually write that function now called complete type phunk complete wups and incomplete.

150
00:08:54,430 --> 00:09:01,100
We're going to basically pass in a transaction of type S-K payment transaction.

151
00:09:01,930 --> 00:09:06,970
And inside this what we're going to do is we're going to use a switch to go through the transaction

152
00:09:07,450 --> 00:09:09,880
identifier so let's do that switch

153
00:09:12,580 --> 00:09:18,150
switch transaction dot payment.

154
00:09:18,610 --> 00:09:20,710
What does the identifier product identifier.

155
00:09:21,010 --> 00:09:23,170
And we're going to do a couple of different cases.

156
00:09:23,170 --> 00:09:28,990
One is IAP M.I.T. and we're going to break at the end.

157
00:09:29,230 --> 00:09:35,130
Then we have another case IAP hydrides adds ID and of course we're going to break at the end.

158
00:09:35,530 --> 00:09:36,620
So that's cool.

159
00:09:36,640 --> 00:09:39,240
So it's telling us the switch must be exhaustive.

160
00:09:39,240 --> 00:09:41,340
So we need to add a default case.

161
00:09:41,350 --> 00:09:42,670
And that's just going to break.

162
00:09:42,830 --> 00:09:43,180
OK.

163
00:09:43,180 --> 00:09:46,100
So anything else is going to break although we don't have anything else to pass in.

164
00:09:46,100 --> 00:09:48,910
So it's never going to get called but it's just a way to be safe.

165
00:09:48,910 --> 00:09:57,670
So now what we're going to do is if Mial idea is called We don't need to do anything but if someone

166
00:09:57,670 --> 00:10:00,640
buys this hide adds ID purchase.

167
00:10:00,640 --> 00:10:05,200
We need to be able to set that user defaults boolean to be true or false and we're going to set it to

168
00:10:05,200 --> 00:10:07,170
False later on.

169
00:10:07,390 --> 00:10:13,870
For instance if the app opens and they've never bought it before so we're going to go ahead and write

170
00:10:13,870 --> 00:10:25,360
a function to set that so-call funk set non consumable purchase status of type Boolean.

171
00:10:25,690 --> 00:10:26,240
All right.

172
00:10:26,350 --> 00:10:30,440
And you know what we don't need this parameter so we're going to just use an underscore.

173
00:10:31,060 --> 00:10:38,520
Now in order to actually set it we call user defaults dot standard set and take a look.

174
00:10:38,530 --> 00:10:43,720
We can set a value of type Boolean for a certain string and we're going to pass in the status from our

175
00:10:43,720 --> 00:10:47,580
function and the key is non consumable purchase was made.

176
00:10:47,590 --> 00:10:49,850
And I just paste it back so I saved it from before.

177
00:10:50,140 --> 00:11:01,450
So if IAP hydrides adds ID is called we're going to go ahead and call set non consumable purchase and

178
00:11:01,450 --> 00:11:07,510
it's going to be true and therefore this is going to be true and set in user default which is really

179
00:11:07,510 --> 00:11:08,530
cool.

180
00:11:08,530 --> 00:11:15,600
Now later we're going to use this to show or hide our ad in our detail visi.

181
00:11:15,790 --> 00:11:17,200
That's pretty neat.

182
00:11:17,200 --> 00:11:21,640
Now let's think if there are any other places that we should be thinking about using this.

183
00:11:21,640 --> 00:11:26,510
We come in oh well you know we need to call complete because otherwise we can't do anything.

184
00:11:26,770 --> 00:11:31,820
So go ahead and just call complete and the transaction is the transaction.

185
00:11:31,820 --> 00:11:34,050
So when we pass and hear from our for loop.

186
00:11:34,090 --> 00:11:38,480
So basically this should set our Boullion to be true.

187
00:11:38,830 --> 00:11:42,130
Yes that's cool so it gets set when we buy.

188
00:11:42,130 --> 00:11:43,750
Otherwise it's false by default.

189
00:11:44,140 --> 00:11:45,700
And that's great.

190
00:11:45,700 --> 00:11:48,350
So let's think how are we actually going to use this.

191
00:11:48,370 --> 00:11:51,790
We need a way to show or hide the ads.

192
00:11:51,790 --> 00:11:56,800
But what if you know someone has purchased the ad and they close out of the app and they go back in

193
00:11:57,280 --> 00:12:02,020
what are we going to use in order to actually show that person that their purchase was valid.

194
00:12:02,020 --> 00:12:07,240
We can basically create a variable that stores the value of that user defaults boolean and then use

195
00:12:07,240 --> 00:12:10,290
that to determine whether or not the ads are showing.

196
00:12:10,480 --> 00:12:15,280
So to do that we're going to make a private variable because no one else needs to use it except this

197
00:12:15,280 --> 00:12:16,160
class.

198
00:12:16,210 --> 00:12:21,540
So say private var hidden status type Boolean.

199
00:12:21,820 --> 00:12:29,710
It's going to be equal to user defaults dot standard dot Boolean for key and the key is non consumable

200
00:12:29,710 --> 00:12:33,640
purchase was made which of course returns a boolean obviously.

201
00:12:33,700 --> 00:12:35,900
So now we have a hidden status.

202
00:12:36,160 --> 00:12:40,630
And when the view appears we can use that property to tell whether or not the ad should be showing or

203
00:12:40,630 --> 00:12:40,930
not.

204
00:12:40,930 --> 00:12:43,960
So go ahead and say View will appeal.

205
00:12:44,680 --> 00:12:47,550
OK Super view will appear and pass in animated.

206
00:12:47,830 --> 00:12:53,560
Then we're going to go ahead and say ugly ad view is hidden and we're going to set it to be equal to

207
00:12:53,560 --> 00:12:58,690
hidden status because if it's either true or false it will show or hide then we're going to go ahead

208
00:12:58,720 --> 00:13:03,410
and set the ads button to hide ads button is hidden.

209
00:13:03,640 --> 00:13:07,860
It's going to be also a hidden status hidden status.

210
00:13:07,870 --> 00:13:08,730
There we go.

211
00:13:09,040 --> 00:13:13,480
So if we buy it and we bring up this view it's going to be hidden depending on whether or not we've

212
00:13:13,480 --> 00:13:15,550
bought it which is really cool.

213
00:13:15,730 --> 00:13:17,920
But let's think we need to set it.

214
00:13:17,950 --> 00:13:23,380
If it is actually purchased because remember when it's purchased that by item gets you know popped in

215
00:13:23,380 --> 00:13:25,740
here the meal is successfully purchased.

216
00:13:25,780 --> 00:13:29,180
But what if we bought hide hide ads.

217
00:13:29,590 --> 00:13:33,400
What if we bought the hide ads in at purchase what we're going to need to do is we're going to need

218
00:13:33,400 --> 00:13:36,920
to call this gay ugly ads.

219
00:13:36,920 --> 00:13:41,210
View is equal to a hidden status and you know what we can consolidate this into a function.

220
00:13:41,210 --> 00:13:43,510
Let's go ahead and put that right here.

221
00:13:43,760 --> 00:13:47,650
Funk and let's just say I don't know

222
00:13:50,390 --> 00:13:57,760
show or hide ads and we can just set that to be equal to hidden status.

223
00:13:57,770 --> 00:14:03,640
So let's go back and put it on view will appear show or hide ads.

224
00:14:03,650 --> 00:14:06,840
And then whenever it's called we're going to go ahead and just show or hide ads.

225
00:14:06,890 --> 00:14:10,940
So we don't need to copy the same code over and over again we can just call the function twice.

226
00:14:11,090 --> 00:14:15,940
So I don't know about you but I really want to go try this out let's build and run.

227
00:14:16,010 --> 00:14:19,340
Let's go see if it works when we buy our at purchase.

228
00:14:19,340 --> 00:14:21,790
And guys this is awesome.

229
00:14:21,800 --> 00:14:23,420
We're making so much progress.

230
00:14:23,540 --> 00:14:23,980
Here we go.

231
00:14:24,050 --> 00:14:27,140
So if I tap on a food item the ads are there.

232
00:14:27,230 --> 00:14:38,440
Now if I buy it if I tap by when I tap OK it should hide your purchase was successful but nothing happens.

233
00:14:38,440 --> 00:14:39,750
This is interesting.

234
00:14:39,760 --> 00:14:41,500
Now why would that be.

235
00:14:41,740 --> 00:14:44,630
It's saying that we are.

236
00:14:44,860 --> 00:14:46,480
Well you know what let's.

237
00:14:46,570 --> 00:14:50,890
We should actually be printing something to make sure that this is actually coming through de-bug print.

238
00:14:51,280 --> 00:14:58,240
And let's go ahead and just print out ads hidden and I'm actually going to go ahead and delete this

239
00:14:58,240 --> 00:15:03,020
app for my phone and rebuild it because now we're using user defaults and it wasn't using that before.

240
00:15:03,190 --> 00:15:06,500
So we're going to build in runs that we have a clean copy.

241
00:15:06,580 --> 00:15:12,730
Although I just deleted it while it was running so X code is going to get mad at me for quit that pull

242
00:15:12,730 --> 00:15:16,570
up an X code beta we go.

243
00:15:16,690 --> 00:15:17,020
All right.

244
00:15:17,020 --> 00:15:21,010
BuildOn Ron go back to our detailed Visi there.

245
00:15:21,340 --> 00:15:22,940
Oh and it didn't say my de-bug print.

246
00:15:23,080 --> 00:15:24,200
How nice.

247
00:15:27,470 --> 00:15:31,840
OK we're going to say ads hidden.

248
00:15:32,810 --> 00:15:33,680
And let's go ahead.

249
00:15:33,680 --> 00:15:35,400
I didn't build it with that in it.

250
00:15:35,410 --> 00:15:37,730
But let's go ahead and hide those ads.

251
00:15:38,000 --> 00:15:39,590
You can't see what I'm doing can you.

252
00:15:39,590 --> 00:15:40,720
Here we go.

253
00:15:40,760 --> 00:15:41,170
OK.

254
00:15:41,250 --> 00:15:43,600
Tap by tap.

255
00:15:43,650 --> 00:15:44,380
OK.

256
00:15:45,300 --> 00:15:50,970
And it says your purchase was successful although it's still not hiding.

257
00:15:51,090 --> 00:15:54,240
And the reason for that could be in our IP service.

258
00:15:54,240 --> 00:15:59,340
Let's see we are completing our transaction.

259
00:15:59,480 --> 00:16:02,220
K we are oh you know what.

260
00:16:02,260 --> 00:16:07,760
The notification is being sent before we're actually completing and setting this.

261
00:16:07,840 --> 00:16:10,350
So it's asking it to do something and to show and hide.

262
00:16:10,360 --> 00:16:12,360
But we have not yet actually said it.

263
00:16:12,400 --> 00:16:17,550
So let's go ahead and let's call complete before send notification Let's see if that helps.

264
00:16:17,590 --> 00:16:26,210
Let's build and run again and let's see if that helps with our issue here of setting that value IAP

265
00:16:26,310 --> 00:16:28,480
products Loden Here's our app.

266
00:16:28,590 --> 00:16:29,700
And let's see.

267
00:16:30,060 --> 00:16:31,050
And the ads are gone.

268
00:16:31,050 --> 00:16:31,700
Look at that.

269
00:16:31,740 --> 00:16:32,870
OK so that's good.

270
00:16:32,880 --> 00:16:36,930
Looks like it's working but I am going to go ahead and stop this.

271
00:16:36,930 --> 00:16:38,760
Delete the app really quickly.

272
00:16:38,760 --> 00:16:43,740
And we're going to build it one more time just to make sure that it is actually working the way that

273
00:16:43,740 --> 00:16:44,840
we are intending.

274
00:16:44,950 --> 00:16:45,580
OK.

275
00:16:46,080 --> 00:16:46,940
So here we go.

276
00:16:46,950 --> 00:16:49,900
It's up there it's running ads are here.

277
00:16:50,040 --> 00:16:59,890
Let's tap hide and buy already bought it and upon a successful purchase they're still not hiding.

278
00:16:59,900 --> 00:17:04,070
So that's interesting it looks though like it is working which is good.

279
00:17:04,490 --> 00:17:09,940
And when we call complete we are setting the non consumable purchase.

280
00:17:10,040 --> 00:17:13,910
And we know it's working because when we reloaded the app and went into the View Controller Actually

281
00:17:13,910 --> 00:17:15,380
I might be able to just do it like this.

282
00:17:15,380 --> 00:17:16,360
I just closed it.

283
00:17:16,580 --> 00:17:20,520
And if I go back in you'll see the ads are gone but they're not removing.

284
00:17:20,570 --> 00:17:21,440
When we buy it.

285
00:17:21,440 --> 00:17:23,600
So let's go back into detail visi.

286
00:17:23,780 --> 00:17:28,430
Let's figure out what the issue is when we purchase this.

287
00:17:28,430 --> 00:17:32,060
It says ads are hidden which That's cool.

288
00:17:32,060 --> 00:17:42,220
It calls show or hide adds and ugly ad is dependent on the hidden status which is initialized here.

289
00:17:42,460 --> 00:17:43,100
OK.

290
00:17:43,310 --> 00:17:50,210
We set it to be that boolean value which we actually set that in the previous few controllers so that's

291
00:17:50,330 --> 00:17:51,330
good.

292
00:17:51,860 --> 00:18:00,140
And oh you know what I just realized this is not working because when.

293
00:18:00,400 --> 00:18:00,850
Yeah.

294
00:18:00,880 --> 00:18:04,090
OK so hidden status is good for when we open the app up.

295
00:18:04,450 --> 00:18:11,470
But it's not good for when it's not good for when we are using it right on the screen because at that

296
00:18:11,470 --> 00:18:16,680
time this has already been instantiated with whatever value was saved when the app opens.

297
00:18:16,690 --> 00:18:19,230
So let's go ahead and let's actually change.

298
00:18:19,240 --> 00:18:19,710
Sure.

299
00:18:19,770 --> 00:18:26,830
Sure hide ads is fine for view will appear but in here we actually need to hard code this to have a

300
00:18:26,830 --> 00:18:28,120
different value.

301
00:18:28,150 --> 00:18:34,150
We're going to go ahead and type right here show or hide ads and if it's purchased we're going to set

302
00:18:34,240 --> 00:18:35,930
is hidden to true.

303
00:18:36,280 --> 00:18:38,020
And we're going to set is hidden to true.

304
00:18:38,260 --> 00:18:42,460
So we are sort of hard coding that in here but it's going to be able to make an instantaneous change

305
00:18:42,970 --> 00:18:45,560
as opposed to needing to quit the app and go back in.

306
00:18:45,580 --> 00:18:46,760
That's not a good experience.

307
00:18:46,870 --> 00:18:52,990
So close it and I'm going to delete it like so BuildOn run one more time and this should successfully

308
00:18:53,050 --> 00:18:56,470
allow us to purchase and hide those ads that I was talking about.

309
00:18:56,540 --> 00:19:03,750
We know it's going to pull up boom let's tap buy or hide ads for 99 tap by tap.

310
00:19:03,760 --> 00:19:04,500
OK.

311
00:19:06,030 --> 00:19:08,690
Do you see that boom ads are gone.

312
00:19:08,690 --> 00:19:11,210
They're saved into user defaults so we can go in.

313
00:19:11,210 --> 00:19:12,560
It's going to be gone.

314
00:19:12,560 --> 00:19:16,860
If I quit out of the app and go back in it's still gone.

315
00:19:16,870 --> 00:19:18,460
Look at that user default is awesome.

316
00:19:18,460 --> 00:19:24,920
So guys we now have non consumable purchases and consumable purchases completely finished.

317
00:19:24,940 --> 00:19:29,590
The only thing we need to do next is to set up our restore function which is going to allow us to restore

318
00:19:29,590 --> 00:19:32,980
our purchases if we downloaded the app on maybe a new phone or new device.

319
00:19:33,000 --> 00:19:35,550
We are so close to being done with this course guys.

320
00:19:35,560 --> 00:19:36,210
Amazing work.

321
00:19:36,210 --> 00:19:38,640
Let's move on to the next video.

322
00:19:38,650 --> 00:19:40,050
I'll see you there.
