1
00:00:07,180 --> 00:00:10,310
Everybody what's going on this is Caleb with Debb slopes dot com.

2
00:00:10,320 --> 00:00:15,670
And in this video we're going to safeguard your app from thieves and from people who are trying to commit

3
00:00:15,670 --> 00:00:18,660
fraud by stealing in-app purchases in your app.

4
00:00:18,850 --> 00:00:22,840
This is a must do for in-app purchases.

5
00:00:22,960 --> 00:00:27,730
I don't know about you but if you know anything about the jailbreak iPhone scene you know that it's

6
00:00:27,730 --> 00:00:32,860
not difficult for people to install an extension on their phone that allows them to basically get in-app

7
00:00:32,860 --> 00:00:34,780
purchases for free.

8
00:00:34,780 --> 00:00:41,020
Now if you have verification like what we're going to set up they cannot actually download those purchases

9
00:00:41,020 --> 00:00:44,210
and you can actually lock them out of the app if you wanted to.

10
00:00:44,740 --> 00:00:49,300
What we're going to do is we're basically going to take the receipt that's generated when we make a

11
00:00:49,300 --> 00:00:53,530
purchase on our phone we're going to upload it to iTunes and make sure that it checks out.

12
00:00:53,560 --> 00:00:58,810
And if it doesn't we're going to basically allow the purchase to say not successful or it's going to

13
00:00:58,810 --> 00:01:05,130
appear not successful because they're using one of those jailbreak tweaks to steal the in-app purchases

14
00:01:05,140 --> 00:01:07,960
so this is a way to prevent that from happening to you.

15
00:01:07,960 --> 00:01:09,470
This is your money maker right.

16
00:01:09,480 --> 00:01:13,000
This is this could be your business and you don't want people stealing from you.

17
00:01:13,000 --> 00:01:17,950
So go ahead and pull open your ex code project and we're going to write a really cool function in our

18
00:01:17,970 --> 00:01:25,060
IP service that's going to upload our app store receipt to iTunes and then we're going to get a response

19
00:01:25,060 --> 00:01:27,260
back whether or not it's legit.

20
00:01:27,280 --> 00:01:31,890
So go ahead and write here below restore purchases.

21
00:01:31,960 --> 00:01:33,690
We're going to create a new function.

22
00:01:34,480 --> 00:01:37,000
And that function is just going to be called upload receipt.

23
00:01:37,120 --> 00:01:40,690
So go ahead and type phunk upload receipt.

24
00:01:41,360 --> 00:01:42,030
OK.

25
00:01:42,460 --> 00:01:47,230
And we're going to need to use a completion handler here because we're going to need to basically escape

26
00:01:47,560 --> 00:01:51,950
a boolean value out that is either true or false if it's valid.

27
00:01:52,120 --> 00:02:01,180
So go ahead and type completion handler wups put a call in and then we're going to make it an escaping

28
00:02:01,180 --> 00:02:07,060
completion handler which basically means that we can send values out of the scope of the closure to

29
00:02:07,060 --> 00:02:08,820
wherever this function is actually called.

30
00:02:08,830 --> 00:02:14,150
So go ahead and type at escaping with a lowercase like so.

31
00:02:14,410 --> 00:02:20,620
And we're going to go ahead and basically use this little function here to call a boolean and that's

32
00:02:20,620 --> 00:02:22,630
where we're going to pass in our boolean value.

33
00:02:22,840 --> 00:02:24,820
And we're not going to return anything.

34
00:02:24,820 --> 00:02:29,060
So we're just going to say return void because we're not returning anything specifically.

35
00:02:29,110 --> 00:02:32,190
So very cool there's our completion handler.

36
00:02:32,350 --> 00:02:39,270
And now what we're going to do is we're going to access First of all the receipt you all from our phone.

37
00:02:39,280 --> 00:02:44,710
Believe it or not when you make a purchase on an app purchase a little you or L gets stored in the main

38
00:02:44,710 --> 00:02:51,390
bundle and then you can use that to pass up to the iTunes store and say Hey check this out is this good.

39
00:02:51,670 --> 00:02:56,920
So let's be let's be safe and use guard Latt because sometimes there might not be a receipt you are

40
00:02:56,920 --> 00:03:01,780
Al maybe you open the phone for the first time and you don't have a receipt or else you don't know whether

41
00:03:01,780 --> 00:03:03,060
or not you're good to go.

42
00:03:03,220 --> 00:03:11,230
So let's use guard let guard let And let's just say reseat you RL and to get that we're going to access

43
00:03:11,320 --> 00:03:15,370
the bundle we're going to go into the main bundle and check this out.

44
00:03:15,370 --> 00:03:18,120
There's something right there called app store receipt.

45
00:03:18,130 --> 00:03:22,830
You r l k the file u r l for the bundles AppStore receipt.

46
00:03:23,020 --> 00:03:26,370
Push enter and then type a comma.

47
00:03:26,500 --> 00:03:28,870
OK because we're going to create another property as well.

48
00:03:28,900 --> 00:03:30,450
Now we have the receipt you are Elb.

49
00:03:30,460 --> 00:03:33,390
Now we need to generate the receipt using data.

50
00:03:33,400 --> 00:03:41,770
So go ahead and type let receipt and that's going to be equal to data and we're going to use the data

51
00:03:41,800 --> 00:03:44,560
contents of function here.

52
00:03:44,560 --> 00:03:46,080
Contents of you l.

53
00:03:46,270 --> 00:03:50,890
Select the one that throws and if you know what that means that means we're going to have to use try

54
00:03:50,890 --> 00:03:51,630
at the beginning.

55
00:03:51,790 --> 00:03:53,110
We'll get to that in a second.

56
00:03:53,200 --> 00:04:02,770
So just choose data contents of the U R L is going to be receipt you r l it's not accessible to us yet.

57
00:04:02,810 --> 00:04:09,200
There we go receipt you r l k now what we need to do in order to actually use this is we need to encode

58
00:04:09,200 --> 00:04:18,110
it using base 64 encoding case to check it out type dot base 64 encoded string and it might not show

59
00:04:18,110 --> 00:04:18,560
up.

60
00:04:18,770 --> 00:04:20,920
But when an auto completes you'll see that it works.

61
00:04:20,960 --> 00:04:26,080
And basically what this is going to do is it's going to take our string value and it's going to encode

62
00:04:26,080 --> 00:04:30,500
it as a base 64 string and that's what we need to pass it up to iTunes.

63
00:04:30,500 --> 00:04:32,740
It needs to be base 64 encoded.

64
00:04:32,750 --> 00:04:35,320
Now of course if neither of these work we're going to call.

65
00:04:35,320 --> 00:04:36,340
Else.

66
00:04:36,830 --> 00:04:42,980
And inside this ELSE block is where we're going to basically send our completion handler a false return.

67
00:04:42,980 --> 00:04:46,010
Because obviously there was no receipt to return.

68
00:04:46,010 --> 00:04:52,040
So we're going to go ahead and call completion and then send it false like that.

69
00:04:52,040 --> 00:04:56,940
Then of course at the very end we need to return OK to get out of our guard let.

70
00:04:56,990 --> 00:05:01,920
But basically we're telling it hey there's no receipt you have not bought a subscription.

71
00:05:02,210 --> 00:05:07,610
So that's one thing we can do to safeguard ourselves against hackers and we can also just to you know

72
00:05:07,610 --> 00:05:13,910
for now de-bug print and just say no receipt.

73
00:05:15,170 --> 00:05:18,700
And that's just the way that we can print out to the console to show us what's going on.

74
00:05:19,010 --> 00:05:20,690
So very cool.

75
00:05:20,690 --> 00:05:26,080
It's going to yell at us because we have to call try because this can throw errors.

76
00:05:26,090 --> 00:05:28,940
So go ahead and just call it try and put a question mark.

77
00:05:28,940 --> 00:05:31,830
Meaning it's going to optionally try because we're in a guard lab.

78
00:05:32,330 --> 00:05:38,270
And if it does get that back we're going to have a variable of type data that we can do stuff with.

79
00:05:38,270 --> 00:05:38,800
OK.

80
00:05:39,020 --> 00:05:39,740
So next.

81
00:05:39,740 --> 00:05:41,990
Go ahead and return down a little ways.

82
00:05:42,170 --> 00:05:49,310
And what we need to do is we need to create a Jaison object that's going to be sent up to iTunes and

83
00:05:49,310 --> 00:05:54,290
then iTunes is going to verify that and send us down all the important Jason information all about our

84
00:05:54,290 --> 00:05:55,430
subscription.

85
00:05:55,430 --> 00:06:01,790
So let's create that Jason object by typing let it lapse let body like so and we're going to use an

86
00:06:01,850 --> 00:06:08,840
open bracket here and a close bracket there and then inside the body we're going to give a key of type

87
00:06:08,840 --> 00:06:11,990
string and a value using some of our values.

88
00:06:11,990 --> 00:06:19,080
So let's go ahead and just say in quotes receipt receipt dash data.

89
00:06:19,110 --> 00:06:23,700
Make sure you get this right because these are the parameters that iTunes once and the receipt data

90
00:06:23,700 --> 00:06:29,680
we already kind of used here with data and our receipt properties so go ahead and just pass in receipt.

91
00:06:30,060 --> 00:06:34,080
OK then we're going to go ahead and type password.

92
00:06:34,080 --> 00:06:40,080
This is another thing and you need a specific password in order to actually upload this type password.

93
00:06:40,680 --> 00:06:44,880
And this is where we need to create what is called an app secret.

94
00:06:45,020 --> 00:06:45,550
OK.

95
00:06:45,780 --> 00:06:49,350
That can be found on iTunes Connect So pull open your iTunes Connect.

96
00:06:49,350 --> 00:06:54,370
Go into my apps like so select the app that you're working on.

97
00:06:55,380 --> 00:06:58,650
Select features and it'll load in-app purchases.

98
00:06:58,660 --> 00:07:02,040
But check this out app specific shared secret.

99
00:07:02,460 --> 00:07:07,530
You can click on this and it will pop up a prompt and you click on generate.

100
00:07:07,530 --> 00:07:09,770
Then you can copy that and paste it into your project.

101
00:07:09,780 --> 00:07:13,520
But you'll see that I already have one saved here so I'm just going to copy it.

102
00:07:13,530 --> 00:07:17,380
But all you'll need to do is just click on the generate button and it'll make one for you.

103
00:07:17,400 --> 00:07:20,510
So this is my shared secret I'm going to go ahead and copy it.

104
00:07:20,510 --> 00:07:24,870
And at the time of this video this is my secret but I regenerated it right after this course so it's

105
00:07:24,870 --> 00:07:26,070
no longer the same.

106
00:07:26,100 --> 00:07:27,330
So you're gonna have to make your own.

107
00:07:27,330 --> 00:07:33,390
So go ahead and copy this and then go back to X code go into Constance and we're going to actually create

108
00:07:33,390 --> 00:07:38,210
a constant here for our app secret just so that we can use it throughout our app.

109
00:07:38,220 --> 00:07:46,110
So go ahead and type let app secret and set that there in quotes so it's a string.

110
00:07:46,400 --> 00:07:47,060
OK.

111
00:07:47,520 --> 00:07:50,760
Then go back to IAP service and we can pass it.

112
00:07:50,760 --> 00:07:52,170
Our app secret.

113
00:07:52,730 --> 00:07:53,210
OK.

114
00:07:53,310 --> 00:07:55,830
Now build it to make sure that that comes through.

115
00:07:55,920 --> 00:07:57,260
Very cool.

116
00:07:57,330 --> 00:08:00,950
And of course after this object we need a comma to separate the two.

117
00:08:01,080 --> 00:08:05,300
But this is an object that we can convert to Jaison and then pass up to iTunes.

118
00:08:05,310 --> 00:08:08,790
So to do that we're going to create another property called Body data.

119
00:08:08,820 --> 00:08:12,210
Go ahead and type let body data.

120
00:08:12,210 --> 00:08:18,240
And this is going to be equal to a Jaison object and we're going to use some of Apple's very cool Jason

121
00:08:18,240 --> 00:08:20,270
serialization classes to do that.

122
00:08:20,490 --> 00:08:25,560
So go ahead and type Jay sun serialization dot and you'll see there's a lot of different options.

123
00:08:25,560 --> 00:08:33,150
What we can say Dot data with Jaison object are based on object here is body and the options we can

124
00:08:33,150 --> 00:08:38,400
pass in are many but we're just going to go ahead and just pass in an empty array because it does ask

125
00:08:38,400 --> 00:08:39,070
for an array.

126
00:08:39,120 --> 00:08:44,880
The options will have a key and a value but you'll see we're getting an error here it says can call

127
00:08:44,890 --> 00:08:48,660
throe but it's not marked with try and the error is not handled.

128
00:08:48,660 --> 00:08:54,250
So to fix this we're just going to go ahead and call try and build it and make sure that that works.

129
00:08:54,270 --> 00:08:55,080
Oh whoops sorry.

130
00:08:55,170 --> 00:08:59,780
We're going to go head and called Try and then force tried because we already know this is valid Jaison

131
00:09:00,300 --> 00:09:03,180
and we already know that we can serialize it properly.

132
00:09:03,180 --> 00:09:07,740
OK so that's why we're force on wrapping it there if we build it you'll see we just get a warning saying

133
00:09:07,740 --> 00:09:09,450
that we haven't yet used the data.

134
00:09:09,540 --> 00:09:10,320
That's true.

135
00:09:10,800 --> 00:09:12,000
So let's use it.

136
00:09:12,000 --> 00:09:18,060
We're going to go ahead and basically create a U R L A U R L request and then we're going to pass it

137
00:09:18,060 --> 00:09:19,800
into u r l session.

138
00:09:19,800 --> 00:09:23,490
Upload this and then asked to see if we get a response from Apple.

139
00:09:23,610 --> 00:09:26,980
So go ahead and let's create a URL here type.

140
00:09:27,050 --> 00:09:35,000
Let u r l and that's going to be equal to u r l and we're going to create it with a string just like

141
00:09:35,000 --> 00:09:35,960
so.

142
00:09:36,210 --> 00:09:39,350
Push enter and the string you're going to have to copy this.

143
00:09:39,350 --> 00:09:42,330
Exactly K type H.

144
00:09:42,480 --> 00:09:45,210
Colon backslash backslash only two T's.

145
00:09:45,240 --> 00:09:48,980
Sorry and you're going to type sandbox.

146
00:09:49,170 --> 00:09:52,300
ITunes.

147
00:09:52,330 --> 00:09:57,380
Apple dot com slash verify receipt.

148
00:09:57,730 --> 00:09:58,300
OK.

149
00:09:58,600 --> 00:10:05,500
That is the string that we're going to use to instantiate a u r l to pass in our Jason object so force

150
00:10:05,500 --> 00:10:07,010
on raptus because it is a u r l.

151
00:10:07,090 --> 00:10:08,620
We know it's valid.

152
00:10:08,620 --> 00:10:10,790
Now we're going to create a request.

153
00:10:10,840 --> 00:10:11,160
OK.

154
00:10:11,170 --> 00:10:16,270
So create a Yoro request using a variable because we do need to set some properties for it.

155
00:10:16,270 --> 00:10:21,800
So go ahead n type var request equals you Arel request.

156
00:10:21,970 --> 00:10:27,400
And if you instantiate it you can pass in a u r l which we have one u r l k.

157
00:10:27,400 --> 00:10:28,110
Very cool.

158
00:10:28,110 --> 00:10:31,190
Now we need to set up the TTP method.

159
00:10:31,240 --> 00:10:35,060
And what the T P body is when we send it up.

160
00:10:35,080 --> 00:10:44,470
So go ahead and call request dot HTP method and it's going to be equal to post K because we are posting

161
00:10:44,470 --> 00:10:53,080
this up to the sandbox you r l and iTunes K the DP body the actual data we're sending up is our body

162
00:10:53,080 --> 00:10:53,840
data.

163
00:10:53,920 --> 00:10:56,070
So go ahead and type request.

164
00:10:56,130 --> 00:11:03,280
H TTP body and you'll you'll notice it's looking for an example of type data we can give it that by

165
00:11:03,340 --> 00:11:05,160
passing in body data.

166
00:11:05,230 --> 00:11:06,300
Very cool.

167
00:11:06,730 --> 00:11:13,450
So now that we have this all set up we are now ready to basically create a data task using you l session.

168
00:11:13,750 --> 00:11:20,100
We can take our request with our data pass it up to iTunes and then wait for a response.

169
00:11:20,320 --> 00:11:21,730
OK so let's go ahead and do that.

170
00:11:21,730 --> 00:11:22,800
Let's type let.

171
00:11:22,870 --> 00:11:30,180
Task equals your session dot shared session data task.

172
00:11:30,190 --> 00:11:35,380
And you'll notice there are a few options but we want the one with a u r l request and a completion

173
00:11:35,380 --> 00:11:37,510
handler because that's what we did.

174
00:11:37,510 --> 00:11:40,990
We created a u r l request and we want to know the response we get back.

175
00:11:40,990 --> 00:11:49,450
So select that pass in our request which is just called request request that we go and on the completion

176
00:11:49,450 --> 00:11:53,630
handler just press enter and give three names to these three properties.

177
00:11:53,640 --> 00:11:58,570
K this is our data that we get back our response data.

178
00:11:58,570 --> 00:12:02,030
This is our response and this is our error.

179
00:12:02,150 --> 00:12:03,530
OK in case we have one.

180
00:12:03,880 --> 00:12:05,120
Now here's what we're going to do.

181
00:12:05,260 --> 00:12:10,390
If we had an error we're going to go ahead and print that error then we're going to go ahead and just

182
00:12:10,390 --> 00:12:12,990
call complete on our completion handler.

183
00:12:13,090 --> 00:12:19,080
So we're going to go ahead and say if error is not equal to nil because if you notice it was optional

184
00:12:19,710 --> 00:12:22,110
we're passing in a parameter here but it was optional.

185
00:12:22,270 --> 00:12:28,420
If we had an error we're going to go ahead and call debug print and we're going to print out that error.

186
00:12:28,420 --> 00:12:28,900
And you know what.

187
00:12:28,900 --> 00:12:34,390
Before it why don't we put kind of a description here saying error space and then we can print out the

188
00:12:34,390 --> 00:12:36,310
error right beneath it or right behind it.

189
00:12:36,310 --> 00:12:40,760
I mean then if we have an error we're going to go ahead and call completion handler.

190
00:12:40,870 --> 00:12:44,900
OK remember to escape out and say hey not successful.

191
00:12:44,980 --> 00:12:47,950
So completion handler is going to be false.

192
00:12:47,960 --> 00:12:54,120
Ok just like above if we have no receipt false if it comes back with an error.

193
00:12:54,610 --> 00:12:57,650
False because that means that our receipt was not valid.

194
00:12:57,820 --> 00:12:59,090
OK very cool.

195
00:12:59,380 --> 00:13:02,050
So that is great.

196
00:13:02,050 --> 00:13:05,740
So our completion handler is false meaning we're saying hey not good.

197
00:13:05,800 --> 00:13:07,750
It was not a valid receipt didn't work.

198
00:13:07,750 --> 00:13:11,960
Someone tried to steal it and we're going to call our completion handler to be false.

199
00:13:12,070 --> 00:13:17,790
Ok but what if we didn't get an error what if it was good we'll call else.

200
00:13:17,860 --> 00:13:21,570
And now this is where we're going to use our response data.

201
00:13:21,580 --> 00:13:22,230
OK.

202
00:13:22,420 --> 00:13:26,800
So we're going to basically take the response data that was downloaded from the server which includes

203
00:13:26,800 --> 00:13:32,860
lots of vital information like the subscription type the product ID the expiration date et cetera et

204
00:13:32,860 --> 00:13:33,690
cetera.

205
00:13:33,700 --> 00:13:38,860
So go ahead and we're going to create a property for the Jason data that's coming back down like so

206
00:13:38,860 --> 00:13:39,810
by typing.

207
00:13:40,120 --> 00:13:48,250
Let Jaison equals Jaison serialization Jaison object and we actually are going to choose the one with

208
00:13:48,250 --> 00:13:55,230
data and options like so now the data we're going to get from response data just like so.

209
00:13:55,480 --> 00:13:59,620
And the options just like before we don't care about we're just going to go ahead and put some empty

210
00:13:59,620 --> 00:14:02,310
brackets there because it asks for an array.

211
00:14:02,830 --> 00:14:04,110
And that's great.

212
00:14:04,150 --> 00:14:06,190
So we're getting our response data here.

213
00:14:06,190 --> 00:14:07,140
This is awesome.

214
00:14:07,480 --> 00:14:09,250
But you know what.

215
00:14:09,310 --> 00:14:13,330
It's coming in as optional and I don't really want to force unwrap it.

216
00:14:13,330 --> 00:14:15,430
So let's go ahead and set up some constants here.

217
00:14:15,430 --> 00:14:20,340
How about if let error equals error.

218
00:14:20,650 --> 00:14:26,020
We'll just going to print the actual error so that it doesn't come in as optional.

219
00:14:26,050 --> 00:14:26,730
OK.

220
00:14:27,080 --> 00:14:31,060
Then whoops was build this I'm not sure why we're getting some trouble here.

221
00:14:31,070 --> 00:14:33,000
OK then we'll say.

222
00:14:33,010 --> 00:14:34,070
Else if.

223
00:14:34,150 --> 00:14:34,680
Let.

224
00:14:34,720 --> 00:14:35,380
Response.

225
00:14:35,380 --> 00:14:38,470
Data equals response data.

226
00:14:38,470 --> 00:14:43,360
Meaning if we do get a response it'll come in as this constant and we're setting the option of value

227
00:14:43,360 --> 00:14:44,280
to be this constant.

228
00:14:44,290 --> 00:14:46,520
Now I don't have to force on rapid anymore.

229
00:14:46,570 --> 00:14:47,230
OK.

230
00:14:47,410 --> 00:14:53,650
So it's saying that we can't call this because we are trying remember we had to force try up at the

231
00:14:53,650 --> 00:14:58,370
top here so we're going to do the same thing to turn this into adjacent object here.

232
00:15:00,050 --> 00:15:02,370
Just like so very cool.

233
00:15:02,370 --> 00:15:06,860
So now we do download a Jason object but we're not yet using it.

234
00:15:07,050 --> 00:15:07,940
OK.

235
00:15:08,130 --> 00:15:12,930
Now what we're going to need to do is basically to print the Jason and then take a look at it.

236
00:15:12,930 --> 00:15:17,370
We want to see what is actually in there so we know what to pull out.

237
00:15:17,370 --> 00:15:20,850
I'll give you a clue we want to pull out the expiration date because that's going to help us determine

238
00:15:20,850 --> 00:15:23,120
whether or not our subscription is still valid.

239
00:15:23,160 --> 00:15:31,260
But let's just for now go ahead and print the Jason and then basically if this worked if there was no

240
00:15:31,260 --> 00:15:33,450
error we can call completion handler.

241
00:15:33,660 --> 00:15:34,390
True.

242
00:15:34,650 --> 00:15:35,520
Right.

243
00:15:35,520 --> 00:15:36,620
Because we know that it work.

244
00:15:36,630 --> 00:15:37,500
There was no error.

245
00:15:37,520 --> 00:15:39,720
And we successfully printed Jaison.

246
00:15:39,750 --> 00:15:44,060
Now we're getting a warning here and it's saying that task was never used.

247
00:15:44,070 --> 00:15:45,840
This is a big issue.

248
00:15:46,050 --> 00:15:53,700
If we leave it as it is the task will never run because we need to call it Task datt resume.

249
00:15:53,740 --> 00:15:54,330
OK.

250
00:15:54,450 --> 00:15:57,120
That's basically going to start the task for us.

251
00:15:57,120 --> 00:16:02,250
And if it gets suspended it will resume it for us so I don't know about you but I really want to go

252
00:16:02,250 --> 00:16:03,180
try this.

253
00:16:03,180 --> 00:16:09,340
So let's think about where we want to call this we should call this when we make a subscription.

254
00:16:09,360 --> 00:16:11,230
Let's just put it there for now.

255
00:16:11,490 --> 00:16:13,720
Let's go ahead and just call upload receipt.

256
00:16:13,860 --> 00:16:19,310
That's our function we made push enter on our completion handler and just give a name for the boolean

257
00:16:19,320 --> 00:16:21,100
let's just say valid.

258
00:16:21,210 --> 00:16:25,190
If the receipt is valid if valid.

259
00:16:25,980 --> 00:16:30,040
Let's do de-bug print and we'll say what.

260
00:16:30,040 --> 00:16:31,590
What do we want to say.

261
00:16:31,590 --> 00:16:39,180
Subscription is totally valid man otherwise.

262
00:16:39,300 --> 00:16:40,430
Or else.

263
00:16:46,150 --> 00:16:52,210
Let's just say it doesn't look like you bought this.

264
00:16:52,570 --> 00:16:52,850
OK.

265
00:16:52,870 --> 00:16:54,010
So let's build and run.

266
00:16:54,040 --> 00:16:58,450
Let's go and make a transaction and let's just verify that our subscription is valid or we're just going

267
00:16:58,450 --> 00:17:00,310
to check our receipt.

268
00:17:00,400 --> 00:17:05,770
By the way our subscription should be expired because it's been longer than five minutes and here we

269
00:17:05,770 --> 00:17:06,070
go.

270
00:17:06,070 --> 00:17:06,840
So wow.

271
00:17:06,940 --> 00:17:10,270
It looks like it automatically purchased us that for us.

272
00:17:10,270 --> 00:17:12,820
That's not good.

273
00:17:13,240 --> 00:17:15,250
Let's scroll up to the top here.

274
00:17:15,490 --> 00:17:18,280
Yeah it's saying subscription valid purchase was successful.

275
00:17:18,280 --> 00:17:19,340
We did not purchase that.

276
00:17:19,330 --> 00:17:24,280
So it looks like calling this function from here is not a good choice we're not actually going to put

277
00:17:24,280 --> 00:17:24,920
it there.

278
00:17:24,970 --> 00:17:30,010
There's a really helpful delegate method for later but for now look at this we're getting all of our

279
00:17:30,010 --> 00:17:32,310
information there's all the Jaison data.

280
00:17:32,370 --> 00:17:37,100
Here's our expiration date and it looks like it expires in five minutes from when we ordered it right.

281
00:17:37,120 --> 00:17:43,740
1:41 1:44 And of course this hour is always wrong but the minutes are correct.

282
00:17:43,750 --> 00:17:48,660
So guys this is really cool we have a subscription and it's working this is amazing.

283
00:17:48,730 --> 00:17:53,650
So we're going to put it in the right place in a future video but for now we can tell our subscription

284
00:17:53,650 --> 00:17:54,560
is good to go.

285
00:17:54,610 --> 00:17:57,970
We've officially bought it and we can verify it with iTunes.

286
00:17:57,970 --> 00:18:01,510
This is going to prevent you from having people steal your in-app purchases.

287
00:18:01,510 --> 00:18:03,160
Very very cool.

288
00:18:03,160 --> 00:18:06,790
So for now I'm actually going to go ahead and delete this.

289
00:18:06,790 --> 00:18:14,200
And in the next video we're going to write another function that is basically going to extract the expiration

290
00:18:14,200 --> 00:18:19,510
date from this Jason data and we're going to set up that in user defaults so that we can lock down that

291
00:18:19,510 --> 00:18:24,270
expiration date so that we can access the expiration date whenever we need.

292
00:18:24,460 --> 00:18:28,960
And in the next video we're going to write a function that's basically going to extract the expiration

293
00:18:28,960 --> 00:18:32,160
date from the Jason data that we downloaded from Apple.

294
00:18:32,290 --> 00:18:38,200
Once we verified it and we're going to use that Jaison data to essentially save the expiration date

295
00:18:38,380 --> 00:18:44,590
into user defaults so that even if we open the app up we can verify that the current date is still behind

296
00:18:44,620 --> 00:18:46,080
the expiration date.

297
00:18:46,080 --> 00:18:50,550
And that will help us to manage whether or not the subscription is active or expired.

298
00:18:50,550 --> 00:18:51,780
Ok really cool.

299
00:18:51,790 --> 00:18:55,200
So let's go ahead and let's head over to the next video where we're going to write that function.

300
00:18:55,240 --> 00:18:59,770
We're going to write an extension of date and we're also going to write a function to determine whether

301
00:18:59,770 --> 00:19:02,040
or not our our subscription is still active.

302
00:19:02,050 --> 00:19:03,220
Very very cool stuff guys.

303
00:19:03,220 --> 00:19:06,450
Let's head over to the next video and let's do that now.
