1
00:00:05,900 --> 00:00:08,650
Hey what's up everyone Mark Price here at the slopes dot com.

2
00:00:08,660 --> 00:00:14,060
Let's go ahead and just get started making in-app purchases so what I want to do is a little bit of

3
00:00:14,060 --> 00:00:17,550
code cleanup as usual I want to create a new group here.

4
00:00:17,630 --> 00:00:23,390
Just call this controller or control or files in there like view control or at Swift and then I'm going

5
00:00:23,390 --> 00:00:28,650
to open the view control or file click the name and rename it to something more useful.

6
00:00:28,650 --> 00:00:33,130
Let's for instance call this a home VC and press enter.

7
00:00:33,140 --> 00:00:40,040
So and now I want to create a services folder because what I want to do is create in that purchase service

8
00:00:40,110 --> 00:00:49,770
that will manage all the in-app purchases for us so services and we're going to say new file swift and

9
00:00:49,770 --> 00:00:55,380
let's go ahead and call this the purchase manager purchase manager.

10
00:00:55,380 --> 00:00:57,630
Yeah that sounds good.

11
00:00:57,810 --> 00:01:10,840
And then class purchase manager like so and we're going to say static let VAR or not are static let

12
00:01:10,870 --> 00:01:14,840
instance what I meant to say equals purchase manager.

13
00:01:14,850 --> 00:01:19,170
So what we're doing here is we're creating a singleton we're creating one instance of this class in

14
00:01:19,170 --> 00:01:22,550
memory that will be used for the lifetime of the application.

15
00:01:22,740 --> 00:01:26,310
So we can always access it easily without having to create new copies of it.

16
00:01:26,310 --> 00:01:33,230
And one more thing we need to do here is import store kit so we can actually use the at Purchase store

17
00:01:33,240 --> 00:01:36,320
get stuff with me so far.

18
00:01:36,490 --> 00:01:36,850
OK.

19
00:01:36,860 --> 00:01:40,590
So the next thing we need to do is forward in with in-app purchases.

20
00:01:40,620 --> 00:01:46,020
Our class is going to have to need to work with this object.

21
00:01:46,080 --> 00:01:48,800
So I want to put an object here as the parent class.

22
00:01:49,050 --> 00:01:53,340
And what we're going to do is we're going implement some protocols we're going to implement S-K products

23
00:01:53,460 --> 00:02:01,230
request delegate like so and S-K payment transaction observer.

24
00:02:01,620 --> 00:02:02,150
OK.

25
00:02:02,220 --> 00:02:06,950
Those are two very common protocols that work with when working with in-app purchases.

26
00:02:07,080 --> 00:02:07,920
OK.

27
00:02:08,190 --> 00:02:10,420
And what do we want to do.

28
00:02:10,560 --> 00:02:13,700
Well we want to work with in-app purchases but we haven't created any yet.

29
00:02:13,710 --> 00:02:18,260
And also by the way we can click this red button here and they'll implement the functions for us here

30
00:02:18,270 --> 00:02:19,340
which is great.

31
00:02:19,540 --> 00:02:23,610
Move these down so they're where they should be.

32
00:02:23,610 --> 00:02:29,780
So we need to create an app purchase so let's go back to our browser and let's go back to our app.

33
00:02:29,790 --> 00:02:32,970
So iTunes Connect my apps

34
00:02:36,010 --> 00:02:43,060
and what we're going to do is go to Daily Dose depth slopes features in-app purchases and we're going

35
00:02:43,060 --> 00:02:49,540
to create the purchase that's going to be used in our app are just going to be a non consumable OK and

36
00:02:49,540 --> 00:02:54,550
non consumable means that you can only purchase it once which is what we want.

37
00:02:54,640 --> 00:03:00,790
Consumable can be purchased many times like coins for a game things like that in our deficit.

38
00:03:01,240 --> 00:03:03,810
We've had consumable coin purchases.

39
00:03:03,820 --> 00:03:05,630
You can use coins to buy courses.

40
00:03:05,650 --> 00:03:07,390
There's many different ways of making purchases.

41
00:03:07,390 --> 00:03:13,030
You can do auto renewable subscriptions or non renewing subscriptions where you just pay it once up

42
00:03:13,030 --> 00:03:14,000
in advance.

43
00:03:14,230 --> 00:03:17,380
And those are few of the ways you can monetize in your apps.

44
00:03:17,380 --> 00:03:22,990
We're going to create a non consumable click Create reference name is just a reference for you and we're

45
00:03:22,990 --> 00:03:26,690
going to call this remove ads and what's the product.

46
00:03:26,710 --> 00:03:30,820
This is important this is the idea you're going to reference in your code and you should use the same

47
00:03:30,820 --> 00:03:33,610
type of bundle that your app is using.

48
00:03:33,610 --> 00:03:41,980
So calm the slopes got a daily dose not remove ads.

49
00:03:42,010 --> 00:03:44,080
That's what I'm going to call it the price.

50
00:03:44,080 --> 00:03:53,320
Let's make it 399 and content hosting content hosting is when Apple will actually host your purchase

51
00:03:53,350 --> 00:03:57,150
you can upload a package file with information about your purchases.

52
00:03:57,160 --> 00:03:58,440
And so they can host it.

53
00:03:58,510 --> 00:04:03,190
And the reason why you might do this is let me give you a perfect example let's think of the app the

54
00:04:03,390 --> 00:04:05,540
soaps app where you can purchase many courses.

55
00:04:05,620 --> 00:04:09,470
We don't want to have 500 in-app purchases one for every course.

56
00:04:09,490 --> 00:04:12,340
That would be too hard to manage and we'd have to keep making updates.

57
00:04:12,340 --> 00:04:17,240
So instead what we do is we would make let's say five in-app purchases we just with different prices

58
00:04:17,270 --> 00:04:22,350
$25 $29 course purchase purchased course purchase of course purchased just with different price values.

59
00:04:22,710 --> 00:04:23,180
Okay.

60
00:04:23,290 --> 00:04:27,940
And when you buy those you buy them great but what about when you like restore your in-app purchases.

61
00:04:27,940 --> 00:04:33,050
How does it know which courses to give back unless you have your own server managing this.

62
00:04:33,070 --> 00:04:33,900
It's impossible.

63
00:04:33,910 --> 00:04:40,600
So what you can do is you can upload metadata about purchases and it's up to Apple and the host for

64
00:04:40,600 --> 00:04:40,900
you.

65
00:04:40,960 --> 00:04:42,850
And then they'll deliver it to you when you need it.

66
00:04:42,850 --> 00:04:45,030
So you can manage things like that.

67
00:04:45,100 --> 00:04:47,960
We're not going to be doing that pretty complex actually.

68
00:04:48,190 --> 00:04:52,420
And then we have localizations of the different languages that you want to display your purchase name

69
00:04:52,420 --> 00:04:58,870
to Apple of course is the more languages that you translate for or localized in the more cells you will

70
00:04:58,870 --> 00:04:59,350
get.

71
00:04:59,350 --> 00:05:03,570
We are only doing English today because that is the only language that I know.

72
00:05:03,730 --> 00:05:05,280
So the display.

73
00:05:05,290 --> 00:05:07,960
This is what the user is going to see when they make the purchase.

74
00:05:08,140 --> 00:05:17,270
Remove ads and the description permanently remove ads is what we're going to make the description say.

75
00:05:17,530 --> 00:05:26,500
Lastly we do need to have a screenshot here so they can look at the app and so they can look at the

76
00:05:26,500 --> 00:05:28,720
app and say hey where's the purchase.

77
00:05:28,720 --> 00:05:36,610
So what we can do is click our simulator here command s to save a screenshot and let's just drag that

78
00:05:36,620 --> 00:05:44,170
screenshot from the desktop over here into the Choose file slot and you want to give the app review

79
00:05:44,190 --> 00:05:49,350
some notes you have to click the green button to remove ads.

80
00:05:57,720 --> 00:05:59,270
Perfect that has loaded.

81
00:05:59,370 --> 00:06:04,320
And when you're all done here go ahead and we're going to copy this idea by the way and we're going

82
00:06:04,320 --> 00:06:05,540
to click safe.

83
00:06:05,970 --> 00:06:08,090
OK your IT purchase is ready to submit.

84
00:06:08,120 --> 00:06:11,590
If if it said something else like missing made it did it you probably missed something here.

85
00:06:11,700 --> 00:06:17,520
But if it's ready to submit what you can do is go back to the App Store now click your first version

86
00:06:17,520 --> 00:06:21,750
here 1.0 or whatever version you want to submit this with.

87
00:06:21,750 --> 00:06:25,630
Scroll down and in-app purchases.

88
00:06:25,630 --> 00:06:29,740
You want to add all of your in-app purchases here and if you created it correctly you'll see here it

89
00:06:29,740 --> 00:06:34,210
did not create correctly it means or if you don't see here it means it was not created correctly and

90
00:06:34,210 --> 00:06:36,900
there's something missing you need to go back and fix it.

91
00:06:36,910 --> 00:06:41,810
Ours is here which is great so I'm going to click done and then I'm going to click save everything that

92
00:06:41,810 --> 00:06:42,570
we've just done.

93
00:06:42,590 --> 00:06:45,080
You have to do even to test in-app purchases.

94
00:06:45,080 --> 00:06:45,570
OK.

95
00:06:45,740 --> 00:06:49,880
If you do not do all of these steps you can even test it and you're going to run into problems so what

96
00:06:49,880 --> 00:06:50,840
did we do.

97
00:06:50,840 --> 00:06:51,320
OK.

98
00:06:51,470 --> 00:06:55,760
Remember we went into the apps or we clicked features we created a new that purchased them we went back

99
00:06:55,760 --> 00:07:00,980
to the apps or we clicked prepare for submission and we added the in-app purchases to this version so

100
00:07:01,070 --> 00:07:04,460
it can be reviewed by the app by the App Store Team.

101
00:07:04,580 --> 00:07:05,320
OK.

102
00:07:05,840 --> 00:07:06,270
So cool.

103
00:07:06,270 --> 00:07:09,590
We're now ready to work with in-app purchases.

104
00:07:09,590 --> 00:07:13,460
So back in the code okay we can start writing code to work with them.

105
00:07:13,460 --> 00:07:19,580
So first things first is I want to actually store the ID of the in-app purchases here so let IAP move

106
00:07:19,610 --> 00:07:21,910
as equals.

107
00:07:21,980 --> 00:07:26,900
You know if you had more than one minute purchase you would store the ID here or if you are building

108
00:07:26,900 --> 00:07:31,190
a more elegant solution you can actually store all these IDs on your server and you can fetch them from

109
00:07:31,190 --> 00:07:36,260
your server and then you can add more in-app purchases dynamically which is really cool without having

110
00:07:36,260 --> 00:07:37,310
to wait for app.

111
00:07:37,460 --> 00:07:42,920
The app store review OK but ours is going to be hard coded because we only have one game.

112
00:07:43,070 --> 00:07:43,910
Are you with me so far.

113
00:07:43,910 --> 00:07:51,100
So here's are in that purchase and I think we're ready to get started on this.

114
00:07:51,200 --> 00:07:54,140
So let's create a few variables.

115
00:07:54,380 --> 00:08:04,140
We're going to create one called Product request products requests type Eskay products request.

116
00:08:04,150 --> 00:08:11,220
This is going to be requests that not with an S zoomie a request that we send up to the app store K

117
00:08:11,390 --> 00:08:17,470
to get products that are actually going to store an array of products like cell escape product

118
00:08:22,180 --> 00:08:26,710
because after all we're seeing you back all of your product IDs and it comes in the form of an escape

119
00:08:26,710 --> 00:08:27,400
product.

120
00:08:27,490 --> 00:08:28,240
Right.

121
00:08:28,270 --> 00:08:32,030
And the reason why we store these IDs here is so we can match them up.

122
00:08:32,050 --> 00:08:37,730
OK so we can match what we get from the App Store to what we have here in our code.

123
00:08:37,760 --> 00:08:38,390
All right.

124
00:08:38,440 --> 00:08:40,780
So those are products requesters our products.

125
00:08:40,780 --> 00:08:41,900
Great.

126
00:08:41,950 --> 00:08:47,170
The very first thing that we want to do is actually fetch the products we cannot make and end up purchase

127
00:08:47,210 --> 00:08:49,050
unless you have the products from the App Store.

128
00:08:49,090 --> 00:08:51,790
Let me say that again you can't make a purchase.

129
00:08:51,910 --> 00:08:56,230
No user can make a purchase unless the app has spoken to the App Store and actually downloaded your

130
00:08:56,230 --> 00:08:59,650
product IDs for your specific app so we have to do that.

131
00:08:59,680 --> 00:09:02,870
So phunk fetch products.

132
00:09:03,010 --> 00:09:11,230
All right we're going to create a set here so product IDs so which product IDs we want to fetch equals

133
00:09:11,300 --> 00:09:13,040
an asset.

134
00:09:13,330 --> 00:09:15,190
We're going to do the one that says object.

135
00:09:15,190 --> 00:09:19,300
We're going to go ahead and pass in that purchase remove ads.

136
00:09:19,300 --> 00:09:25,790
We're going to cast this as the regular set just the way you got to do it.

137
00:09:26,400 --> 00:09:26,700
OK.

138
00:09:26,720 --> 00:09:30,250
So we have a set of product that is that's how Apple wants them.

139
00:09:30,250 --> 00:09:33,490
Is it an asset or a set of some kind.

140
00:09:33,490 --> 00:09:36,670
And then what we're going to do is we're going to save our request so a product request

141
00:09:39,100 --> 00:09:47,740
products request and we're going to say equals Eskay products request and it wants the product identifiers

142
00:09:47,770 --> 00:09:48,690
and wants that set.

143
00:09:48,710 --> 00:10:00,940
So let's go ahead and create the set so product IDs and then products request delegate equals self care

144
00:10:01,810 --> 00:10:07,290
and products requests dot start.

145
00:10:07,300 --> 00:10:11,620
All right so what's going to happen is you're saying hey let's go fetch some products.

146
00:10:11,650 --> 00:10:13,320
Here's the list of products that I have.

147
00:10:13,360 --> 00:10:16,780
Apple can you go get them for me maybe you don't know all of them maybe have some old one deprecated

148
00:10:16,780 --> 00:10:17,350
ones.

149
00:10:17,410 --> 00:10:19,630
You're letting apple know which products that you want.

150
00:10:19,840 --> 00:10:20,110
OK.

151
00:10:20,110 --> 00:10:23,930
And you make the requests you set the delegate and you click start when you do the delegate.

152
00:10:24,150 --> 00:10:24,530
OK.

153
00:10:24,550 --> 00:10:28,780
It's going to call this function here products request function when it's done.

154
00:10:28,900 --> 00:10:33,010
OK so this function here we don't need to do anything else and when it when the request is done after

155
00:10:33,010 --> 00:10:35,260
we started it we'll call this function.

156
00:10:35,260 --> 00:10:36,400
All right which is cool.

157
00:10:36,700 --> 00:10:40,720
So let's go ahead and make sure that when the app first loads that we're starting the fetch on our products

158
00:10:40,720 --> 00:10:44,180
because we want it to be ready by the time the user actually clicks the button.

159
00:10:44,200 --> 00:10:51,110
So we'll go to the app delegate and what we'll do is here we will say purchase manager for instance

160
00:10:51,330 --> 00:10:54,950
that fetch products the moment the app loads.

161
00:10:54,970 --> 00:10:57,910
All right let's just get all this set up and ready to go.

162
00:10:58,390 --> 00:11:04,330
So now that we've started the request how do we actually store the data when it comes down et cetera.

163
00:11:05,460 --> 00:11:09,730
What we'll do is in here and this function did receive response.

164
00:11:09,810 --> 00:11:10,640
Okay.

165
00:11:11,240 --> 00:11:16,870
When you say response products that count was greater than zero meaning did it find products if there's

166
00:11:16,890 --> 00:11:21,160
more than one great let's go ahead and start working with them and then we're just going to store them.

167
00:11:21,330 --> 00:11:26,810
Products equals response products.

168
00:11:28,290 --> 00:11:31,050
We're not doing a whole lot here with this.

169
00:11:31,050 --> 00:11:33,660
And so I do want to show you something which is really interesting.

170
00:11:33,660 --> 00:11:36,100
OK so response that products count.

171
00:11:36,270 --> 00:11:36,640
OK.

172
00:11:36,660 --> 00:11:40,110
So what is a product that it's giving us here.

173
00:11:40,610 --> 00:11:41,880
It's a type Eskay product.

174
00:11:41,880 --> 00:11:48,180
Well if you look at S.K. product OK there's a there's a title a price a price location product identifier

175
00:11:48,210 --> 00:11:51,600
etc. etc. etc. and you're like Mark why is this important.

176
00:11:51,600 --> 00:11:53,690
Well think about this.

177
00:11:53,880 --> 00:11:58,640
You say you have literally used the dove slopes example let's say you're selling 10 courses and they'll

178
00:11:58,650 --> 00:12:00,980
have different prices and different product IDs.

179
00:12:01,120 --> 00:12:01,910
OK.

180
00:12:02,390 --> 00:12:04,820
Where were you getting the pricing information from.

181
00:12:04,970 --> 00:12:08,540
Well the pricing information has to match what's on Apple's server.

182
00:12:08,550 --> 00:12:15,540
And so Apple needs to send you that information right so you can actually display it in your purchased

183
00:12:15,600 --> 00:12:16,400
icons.

184
00:12:16,410 --> 00:12:20,250
Oh OK so you don't manually write the prices yourself in the code.

185
00:12:20,250 --> 00:12:20,750
No.

186
00:12:20,820 --> 00:12:24,360
You get those prices from the App Store so you can display them to the user.

187
00:12:24,360 --> 00:12:28,680
In our case we're not doing that because we're just clicking a button here that says remove ads but

188
00:12:28,680 --> 00:12:32,550
you do have that information available to you here inside your products.

189
00:12:32,550 --> 00:12:33,020
OK.

190
00:12:33,030 --> 00:12:38,970
Every one of these products has a price and title etc. all coming from the apps are all what you created.

191
00:12:38,970 --> 00:12:39,960
All right.

192
00:12:40,150 --> 00:12:45,570
And all we're doing here is actually just just storing the one in that purchase that we have and where

193
00:12:45,720 --> 00:12:47,650
we can make a purchase later on.

194
00:12:48,030 --> 00:12:49,070
No big deal.

195
00:12:49,190 --> 00:12:49,750
OK.

196
00:12:52,040 --> 00:12:55,310
So that looks good to see if it's actually working.

197
00:12:55,340 --> 00:13:08,240
What we can do is in here we can print response products debug description came something very important.

198
00:13:08,300 --> 00:13:13,790
You need to know right now you cannot test in-app purchases on the simulator.

199
00:13:13,790 --> 00:13:16,550
Again you cannot test in-app purchases on the simulator.

200
00:13:16,760 --> 00:13:18,700
Even the request to fetch products won't work.

201
00:13:18,710 --> 00:13:20,470
It will not work in the simulator store.

202
00:13:20,490 --> 00:13:27,260
It does not work in the simulator so if you don't have a device you can't test in-app purchases and

203
00:13:27,260 --> 00:13:31,820
I would never ever recommend submitting an app to the apps or unless you have a device and you've actually

204
00:13:31,820 --> 00:13:32,500
tested it.

205
00:13:32,510 --> 00:13:37,700
So make sure your device is selected and what we're going to do is we're going to look for this print

206
00:13:37,700 --> 00:13:43,280
statement saying which products it was able to pull up from the App Store someone or run it now.

207
00:13:43,340 --> 00:13:49,550
So we can see and again the app delegate is being called to start the fetch products and that should

208
00:13:49,550 --> 00:13:54,870
start this which goes here to the products requests and it will give us a response.

209
00:13:54,890 --> 00:13:58,170
The app is now active and working perfect.

210
00:13:58,170 --> 00:14:03,670
Let's stop it let's look at our prints here.

211
00:14:03,800 --> 00:14:08,860
I saw something that some Google print outs here

212
00:14:11,700 --> 00:14:14,140
and there it is it did return one product for us.

213
00:14:14,220 --> 00:14:15,640
So it's definitely working.

214
00:14:15,690 --> 00:14:22,160
Our one product has been fetched from the iTunes store and we've printed it here.

215
00:14:22,230 --> 00:14:27,120
And so clearly we're receiving an object so let's go ahead and call this video done what we've done

216
00:14:27,120 --> 00:14:31,520
here is we've implemented a connection to the iTunes App Store.

217
00:14:31,650 --> 00:14:37,380
We've successfully fetched one of our advertisements or excuse me one of our in-app purchases by via

218
00:14:37,820 --> 00:14:44,310
via of this idea here and we started the request to fetch the products and we received them right here

219
00:14:44,310 --> 00:14:48,150
and stored them in a variable so we can reference them at a later point in time and make purchase.

220
00:14:48,150 --> 00:14:49,450
So that's it for now.

221
00:14:49,450 --> 00:14:51,400
Marc price Adela's slopes dot com.

222
00:14:51,450 --> 00:14:52,520
Let's move on.

223
00:14:52,650 --> 00:14:53,080
And for.

