In App Purchases Tutorial - Auto Renewable Subscriptions (SwiftUI, iOS)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey code crew in the last swift ui revenue cap video i showed you how easy it is to let users make purchases in your app well in this lesson i want to show you it's just as simple to offer in-app subscriptions revenuecat makes integration and analytics a cinch but before we dive into that let me ask you a quick question have you tried to integrate in-app purchases to your app before is this going to be your first time let me know by leaving a quick comment below and on your way down there please give this video a thumbs up it really helps so thank you all right now let's take a look at how we're going to do this because we've done some of the work already in the previous lesson this is going to be pretty simple it's only going to take three steps number one we have to create the subscription product inside app store connect number two we have to add this subscription product to our revenue cad account and number three we just have to add a couple of code snippets to our xcode project to pull down the subscription info and then to process the transaction now just in case you missed the last video where we created our app inside app store connect and uh signed up for our revenue cad account and added the revenuecat sdk into our xcode project don't worry you can still go through this video however i will provide a link on screen and below in the description if you want to check out that previous video and watch me do those things in detail all right with that said let's go into step one creating the subscription product inside app store connect all right so here i'm in my app store connect account and in the previous lesson we had created an app listing for our demo and we had gone down to the manage portion of in-app purchases and added a couple of one-time purchases this time we're going to add an in-app subscription so let's go ahead and click this little plus icon and choose auto renewable subscription this is the most common type of subscription i think that you'll find and it's the one we're used to you know with netflix and spotify and all of that here we're going to add a reference name and a product id before we do this i do want to mention that revenuecat has an amazing piece of documentation to guide you through this process with a lot of best practices now to save you some time i'll highlight those best practices as we do it together here but i do still think this is worth a read if you're going through it for the first time so i'll make sure i put this link in the description below the video alright so the reference name is just your internal name for your reports so here i'm going to put com mind this is all access monthly and for the product id now this one's pretty important because these product ids identify your in-app purchase across your entire account across all of your apps and even when you remove this app that product id that you've used before is now taken up and you can't repeat it and so it really helps to have an organized system for your product ids the system that revenuecat recommends is to have your app name or maybe some sort of sku or app id so i'm just gonna put cm followed by underscore followed by the the price of this subscription so i'm going to make this let's make this a 14.99 followed by underscore followed by the duration of the subscription so this would be one month and following that if you had any sort of trial or introductory period you could put another underscore and then the duration maybe one week and the price of that so maybe like 99 cents or something like that um but for this one i'm not going to have that so i'm just going to leave it as this product id let's click next next thing to do is to add it to a subscription group so as you can see here i already had created a subscription group during my testing but i'm going to create a new one too to show you what that is now a subscription group is exactly like it sounds it groups together different subscription products that unlock the same level of access so the best example would be if you had let's say a monthly and an a yearly subscription so two different durations but they unlock the same tier or same level of access you can put them into the same subscription group again this is a reference name so this is internal later on we're going to have to configure a public facing name so for this internal name i'm just going to call it command all access because i've already used pro access so let's go ahead and create that and then we're going to get to configuring our subscription now there are only a couple of pieces of information so number one is the duration so this this one is the monthly let's go ahead and choose one month and let's set some pricing actually let's hit save first because these are treated as independent steps and it's going to prompt you to save anyways so i'm going to choose my currency and i'm going to choose 14.99 does that exist yes all right let's click next and here it's going to convert that currency and tell you what the equivalent would be for the different countries and regions now you can adjust the pricing as you wish for each of these places i'm just going to go with the flow here just click create all right i have to save again otherwise it's going to prompt you to then i'm going to click back and we're going to add localization so here you can sort of set the text and what gets displayed depending on the different regions and countries and this is what the user is going to see this is what's going to show up for your subscription name and this is going to be the description for that now you might be tempted here to put something like you know all access monthly 14.99 and put all of this information in here but actually all of that becomes redundant when it gets combined with the app name the subscription group name and all of that so you really need to know the context of how this subscription name is going to be displayed we just checked the documentation real quick because i found this image so useful in the documentation when the user goes to modify their subscription or check the status of it this is how they're going to see the information so you have app name then you have the group name and then you have the subscription name and then you have price and duration and then down below under options and it's sort of cut off here you can see that it's going to be the subscription name followed by brackets and then the duration in there and then the price and i assume that you would be able to switch to a different subscription in the same group right below it so if you had like the yearly access you would see that there that's why you can see in the subscription display name it's redundant to also put the duration and the price definitely bad idea to put the price because that's different for every single user so you don't want to embed the price in the name you can see from this example that their group name is ocean journal subscription and their subscription name is all access there's no mention of duration or price so i'm going to follow the same practice here and i'm going to put all access and then i'm going to say unlocks all x unlocks all content now if i had a yearly subscription product i would put the same thing here right in fact that's one of their tips that they recommend here if you read it i'm not going to read it out to you but it basically says for for all of the subscriptions in the same group just have the same name because that way under options here it's going to say all access and then the duration and then underneath it's going to say all access and then like your yearly or you know another duration all right so let's go back here let's save this and then before we can test this we have to submit some or add some review information because we're not actually submitting this for review yet but one of the things we have to add is a screenshot and i'm going to put a placeholder image here i created this in the previous lesson so you can check that out if you if you missed that for some reason so here's the placeholder screenshot i'm going to hit save and it's still going to say missing metadata but it says you must add yeah so what we're missing is if you go into subscription groups remember how we created that all access subscription group this one right here we only specified an internal reference name we haven't specified yet a public facing name so let's go ahead and click this and add okay so this is the public facing subscription group name let's go back here and check out what that is so again the first piece of information is app name and then the group name and then the subscription name so for the group name they put ocean journal subscription and then uh below that for the actual subscription is all access so i am going to put here call mine subscription and then for the app name display option i'm going to use a custom name rather than specifying the app name because a lot of the times when you do app store optimization you're going to be cramming some keywords and things that you want to rank for in the app name so obviously that's not stuff that you would want in this screen here when the user is looking at the subscription so i'm going to use a custom name and just simply put what the app name is intended to be let's hit save okay now this subscription group is ready to submit i think that might have been the actual subscription though and then down here our subscription uh right here still says missing metadata but sometimes it hasn't picked up yet so i would simply refresh the page and just double check that it's ready to submit all right see we just have to refresh the page alright so this is ready to submit now now we can add it to our revenue cad account so just in case you don't have your revenue cat account yet you can visit codewithchris.com rcat2 that's going to bring you to this page it's just going to let the team know that you guys are interested in more app monetization content i don't get compensated for any account signups or anything like that if you have your account created from the previous lesson definitely use that to log in otherwise you can try for free and create an account you won't get charged or anything like that and it's free to use up to ten thousand dollars in monthly revenue so that's quite generous after you have your account in here you're going to want to add app and then add your app we've done this in the previous lesson so let's click on mine too and if we go into products you'll see that we have two one-time purchase products this time however we're adding a subscription product the process is the same but we're gonna have to do one more configuration which is to add an entitlement before we get there let's just add our subscription product first let's click new and then let's add that identifier so i kind of remember it from memory but it's going to be this one right here and that's going to be your product id and you can see i didn't use that for subscriptions but for a subscription you definitely want to do that and select store let's go app store and click add all right so now we have our product easy zero entitlements so what are entitlements well it's an easy way for us to check whether a user is entitled to a certain level of access so in this case for our meditation demo we unlock all access so let me create a new entitlement in this section right here click new and we're going to call it all access unlocks all content so that's my id for my entitlement this is what i'm going to be checking in my xcode project in my app so if i want to determine if a user has all access then i'm going to make sure that any subscription that unlocks all access has that entitlement configured so for this subscription product let's go and add the new entitlement to it okay that's not where we do it sorry about that we go into entitlements and then we're going to add products to it instead so let's go ahead and click into here and we're going to attach all of the products that would unlock this level of access so let's go to attach and let's go ahead and select our subscription and there we go if we had multiple subscriptions like maybe a yearly subscription we would also attach that here because all of those subscription products unlock this tier this all access tier now offerings is something special as well but we're going to talk about that in the next lesson and that's pretty much all we have to do here now before we jump into xcode to allow users to purchase it i do want to mention one thing just in case this is the first video you're jumping into and you haven't set up your app yet because you need to go into settings here and you need to add your app bundle id as well as your itunes connect shared secret this is what allows revenue cat to go into app store connect here and fetch the information it needs so you would go ahead and click this and then generate a secret key and then you would go back to your settings and you would just add that right here and this bundle id is from your xcode project if you want to see me do this step by step then definitely review the previous lesson in this series all right with that said let's jump into our xcode project and allow users to purchase our new subscription all right so here we have the xcode project for our meditation app demo i'm going to do a quick recap just so we're all on the same page so first of all we added the revenue cat sdk to our xcode project using cocoapods in the last lesson you'll see me go through those exact steps so feel free to revisit that if you've forgotten and then in our entry point here we have created a net method here and we basically imported the purchases framework up here in line 9 and then we called the configure method passing in our api key now this api key is from our revenue cat app in the dashboard as you can see right here okay so with that out of the way let's review how this buying process works because purchasing the subscription is actually the same way that we purchase a one-time purchase um just to remind you this is the details screen for looking at a single meditation now this buy button here uh calls our viewmodel dot make purchase and passes in the meditation that the user is looking at so if i go into that method you'll see that we call this other class purchase service dot purchase and we pass in the product id for the meditation now this purchase service is something that we created and this is the actual revenue cat code so what are we doing here really it starts right here with the revenue cap purchases framework you import that purchases framework and then you get the singleton instance and then you call dot products to fetch an sk product this stands for store kit product based on a product id so this is actually going to fetch that information from app store connect basically how you've configured that product and it's going to pull that information down it's going to look for that product so after that call is made when it returns first of all we check that we did find a product and if we did then we're going to get a reference to it from here and then we're going to call another method in the revenue cat purchases framework so this is the method we call purchase product and we simply pass in that store kit product and we're going to get a response back with a lot of info transaction purchase info error and if the user canceled or not and then right here we're simply running our logic to unlock that purchase for the user inside of our app now that bit is going to be different for your app simply because your logic is going to be different from my logic but really the revenue cap parts of this is first to fetch the sk product and then to actually process that transaction this is exactly the same thing for a subscription so we would pass in the product id for the subscription instead and then it would process that so processing the transaction for the purchase is just one side of the equation on the other side we also have the check access right we have to check if the user has a paid subscription is it active and does he or she have access to all of the content well remember in revenue cat we had created this entitlement called all access so when the user buys that subscription it's going to unlock that entitlement or make it active for them so inside of our app we just need to check to see if they have an active all-access entitlement so the way we do that is where should we do this ourselves so we would do this in the in the meditation model in this case and in here we can check if the user has access um to a subscription or has an active subscription so again we would use the purchases framework from revenue cat and we would say purchases dot shared dot purchaser info okay and if i hit enter it's going to open up this closure so we get back two parameters when we fetch the purchaser info for the user it's going to have this purchaser info object and it's also going to have error so here let's call this purchaser let's just call this info and call this error so inside here check the info parameter for active entitlements yeah so if info dot active subscriptions but what we're really looking for are entitlements here see the entitlements attached to this purchaser info because with this one this is searching for specific active subscriptions so we would have to check against okay does he does he or she have an active monthly subscription or does he or she have an active yearly subscription or do they have this description and that and you're checking against these individual product ids whereas if we use revenue cat and we're just attaching all of those subscriptions to this single entitlement then all we need to do is just check if they have an active all access entitlement and that makes it way easier especially when you're introducing different pricing options and discounted offers but you know all of those things unlock the same level of access you can just add them all to this entitlement and check that so we're going to say uh entitlements uh active actually this might not be the correct method let me just dive back into the documentation uh this is by the way this is really useful they have such good documentation under subscription status here get purchase info this was what i was looking at earlier so with this purchaser info object you can get the entitlement information all right so for example here checking if a user is subscribed the purchaser info.entitlements and then you can pass in the id of your entitlement so for us that would be all access so let's go ahead and do that let me just double check if this was a boolean is active so you gotta check the extra flag there you know to do and this would be unlock all access for the user so that's it this is the other side of the equation so if you're going to make a purchase for a specific subscription all we need is the product id here this one right here and then we can go ahead and use this method to look up the store kit product and once we get a reference to that we can use the purchase product method to actually process that transaction which would then unlock the entitlement or flip it active you know according to what we configure on the dashboard side and then to check access we would just need to get the purchaser info for the user and then check that they have an active entitlement and then we go ahead and unlock everything for the user now in terms of where you put these code snippets and what to do afterwards like how to unlock all the content for the user that's all going to be dependent on your own app so it's really hard for me to show you those specific details especially because this is just a demo app so for the rest of this video i will implement it for this demonstration app but just know that if you were building your own app that you were planning to put into the app store you probably wouldn't do it the way that i'm doing it right now because all i'm because there's no database there's no user directory i'm not saving uh you know what the user has unlocked in a database somewhere for them to you know retrieve later on this is all to demonstrate really how easy it is to process transactions and in-app purchases with the revenue cap framework and then also how to check if the users have active subscriptions so that you can unlock the content okay so with that caveat out of the way let's implement it for this demo app and unlock everything for the user once they have bought a subscription so to recap how this works so far in this demonstration app we have a dictionary that just indicates because we do allow users to purchase single meditations so this dictionary keeps track of which meditations the user has unlocked the string is the meditation id and boolean is just whether or not they have access to that so in the detail view let me resume this this buy button only shows up when it checks that dictionary and sees that the user hasn't bought this before with the subscription we want to unlock everything so i'm going to create an additional flag here and call it all access and i'm going to initially set it to false and basically if the user has an active subscription i'm just going to flip this true and we're not going to show any buy buttons because they have access to everything so when the user when the user has this entitlement i'm going to set this flag to true like that and furthermore in the detail view i am going to i'm going to say if the user has not purchased this meditation and they do not have all access you know all access equals false then show this button i'm also going to add a second button here so i'm just going to copy this actually i'm going to copy copy this and this button is going to be if the user doesn't have an all-access subscription i'm going to show a button that says buy subscription and that's let me see if there's something wrong here okay i'm not exactly sure why that's failing to build let me just build the project and okay build succeeded so anyways we should see a button as soon as that starts to work but um let's just process this subscription so what are we going to do when the user taps on that buy subscription button well right here we're calling model.make purchase and passing in that specific meditation right well i'm going to make another method here instead of make purchase i'm going to say this one's going to be make subscription purchase and seeing as how i only have one subscription right now i'm going to perform purchase purchase service and for the product id i'm going to put it into a constants file right here now in a production app you wouldn't hard code the product id like this you would probably come from your database but uh subscription how about let's call it sub subscription product id okay so this was you know this one right here so that's what we're going to pass in right we're going to pass in uh we're going to pass in constants dot subscription product id and upon successful purchase what do we want to do well all we need to do upon successful purchase is that the all access flag all right so self.all access equals true so that is going to flip the switch on this which will then notify the ui that hey they just bought a subscription so remove all the buy buttons because they have access to everything so back in the detail view we can call that new method model dot make subscription purchase and when they make that subscription purchase and that all access flag gets flipped to true this button is not going to show this by subscription button is not going to show and this button as well by a single meditation this is not going to show as well all right so i'm going to really quickly just run this in the simulator to make sure that my buy subscription button shows up because it wasn't rendering here in the preview canvas okay so indeed it's there but tapping on these buttons doesn't do anything in the simulator we have to plug in our actual device to actually test purchases so that's what i've done right here and you can see my my two girls there i really love this photo because it's it shows how silly they are it's a very dynamic pose so i had to load up my app on the phone right there and let's take a look oh yeah i downloaded tik tok recently uh haven't created any content and barely use that i'm thinking about using it for code with chris because i thought it was mostly you know for entertainment but then recently i've seen content creators actually teaching and and creating learning content on it so i'm interested in exploring that if you use ticktalk or you have some ideas on how i can use tiktok to educate and to teach people coding in ios let me know share with me what sort of content do you think would fit tik tok i'm thinking like short tips and things like that okay anyways here is the demo all right so i'm going to try to make a test purchase on the subscription so tap that button and it will recognize that you are trying to test your in-app purchases so you'll notice that it says sandbox and if this is your first time um trying to test your in-app purchases it's going to pop up a dialog asking for username and password and you have to put in a test account for this so you have to create a sandbox test user in your app store connect we did this in the previous lesson if you don't remember go into app store connect click on users and access along the left hand navigation there will be like a sandbox testers near the bottom click into that add a test account with an email and a password and that's what you're going to enter here on the screen so since for me i've already added my sandbox tester account i only have to enter in a password so here you can see i'm purchasing all access for this app and the details are there that's not my subscription description but yeah so let's go ahead and try and purchase this all right let's hit subscribe okay now let's enter in my password okay sign in right there we go and give it a second okay i'm all set and uh how did it just lose uh how to just lose a connection to that all right so we're back my quicktime recorder just cut out as soon as the action happened we processed the test transaction and then it popped up a little dialogue that said purchase successful you're all set and then i tapped on ok and what i saw on the screen was that the two buttons disappeared what you saw on my screen was quicktime crashing but you're gonna have to take my word for it but what i do want to show you is that now that the user has purchased the subscription if we hit a set a break point right here on the init method of our model let's walk through checking the users entitlements and just make sure that they have access right i'm just going to put breakpoints in a couple of these different places and i am going to run the app on my phone and then let's take a look at what happens all right so it's fetching the purchaser info for this user let me just bring up this and we're gonna just hit continue execution and it's gonna come down here so let's check the let's check the info object here and you can check you can see that under entitlements we do have all access expires date you can see it actually expires quite quickly because when you're testing all the time frames are shortened so when you have a monthly subscription it expires i think in like five minutes if you have a yearly subscription it expires in like half an hour or something like that and see is active yes it's sandbox yes and all of this other metadata so it's going to come into here and it's going to set all access flag to true which basically will unlock everything in our app now again i do want to mention that the most important takeaways from this video is how to work with the revenue cat sdk because the exact implementation of how to unlock stuff for the user is dependent largely on your own app and where you put this code even is largely dependent on your own app implementation but take away how we integrated the revenue cat sdk how we initialized it here with our api key how we fetch the sk product using the product id and then process the transaction and finally how we were able to check if the user is entitled or has that entitlement or not so those are the big takeaways from the video the last thing i want to do is jump back over to our revenue cat dashboard and just check out the purchase so let's go back to overview remember to toggle this the sandbox data and take a look check it out we have one active subscription here active subscriber being me and you can see that this was the initial subscription purchase 20 minutes ago and it expired in five minutes because it's a monthly uh subscription right so that testing time frame is shortened to five minutes and you can see it's already renewed like three times and these indicate that these are renewals now the reason why it expires in such a short time frame is so that you can test what happens during a renewal you don't have to wait a whole you know 30 days for you to test if your app is functioning as expected so that's why there's this as you can see offering in-app subscriptions is just as simple as offering one-time purchases however in the next lesson i want to show you an even better way of presenting your products using offers this feature allows you to configure different combinations of products to present to your users at the optimal time based on conditions that you specify this helps you maximize your revenue because you can be presenting offers to users that actually want them that are relevant versus just presenting generic offers for example if you notice the user is really heavily using your app and still hasn't made a purchase at the end of the week you might have your app present to them a limited time offer with a discount just to tip the scales in the next lesson i'll show you how to use this to get ready make sure you have your free revenue cat account and if you don't have one yet just go to codewithchris.com rcat2 revenuecat is free to use up until you're making 10 000 a month so in my opinion it's a great idea to use them especially in the beginning when you don't know if your app is going to make any revenue at all using revenue cat really cuts down on your development time and helps you get to launch faster again the url is codewithkris.com rcat2 full transparency i don't get compensated for signups but using that link does let the team know that you want to see more app monetization content and they may sponsor future videos here at code with chris so thank you for that and thank you goes out to revenue cat as well for making this video possible all right in the next lesson we're going to take a look at offers if you don't want to miss it make sure you're subscribed and turn on bell notifications give this video a thumbs up too if you enjoyed it thank you so much i'll see you in the next lesson
Info
Channel: CodeWithChris
Views: 13,662
Rating: undefined out of 5
Keywords: in app purchases ios, apple in app purchase, swift in app purchase, in app purchase, ios in app purchase, in app purchase tutorial, ios in app purchase tutorial, in app purchase ios demo, in app purchase ios example, swift add in app purchase, swift in app purchase example, swift in app purchase subscription, swift test in app purchase, swiftui, revenuecat, in-app purchase auto-renewable subscription tutorial, in-app purchase subscription tutorial, Auto Renewable Subscription
Id: EBasaCcHhUs
Channel Id: undefined
Length: 37min 45sec (2265 seconds)
Published: Fri Dec 18 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.