Group Group Group Group Group Group Group Group Group

raywenderlich.com Forums

In-App Purchases: Auto-Renewable Subscriptions Tutorial

You'll learn all about auto-renewable subscriptions in this iOS development tutorial.


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/659-in-app-purchases-auto-renewable-subscriptions-tutorial

Hi, Great tutorial! should i need any more code to implement user’s upgrading from 1 subscription to another or this is done by apple?
thanks

This is covered in the example, in the sample app you can upgrade from 1 selfie a week to all access. The user selects a new subscription plan and you process it with StoreKit. Once the purchase is complete you will have a new entry on the receipt showing their new access level. I believe in the case of a downgrade you will not see that on the receipt until the next recurrence is processed. As with everything it is your responsibility to provide the new/additional content for their upgrade, you are also required to provide it effective immediately.

Awesome tutorial! Do you have any suggestions on how to link purchases to an account on our server? For example, a Netflix auto-renewing subscription in which the user can sign into another device and have his/her subscription accessed/modified.

That’s a tricky one with regards to modifying. I am not aware any API that your web site or non-apple device can use to modify the subscription. I believe that has to go through StoreKit or Apple’s web interface. So there’s some education you’d have to do for your users here.

As far as linking, the route I would take is to have the user’s device upload their receipt data to your server and link that to their account record on your system. From there, your server submits the receipt data to Apple’s API to validate it, I would make this a recurring background job for your server to do regularly to make sure that the user has not cancelled their subscription, downgraded, upgraded or cross-graded. From here I would gate all content access using your server so that on any other device the user signs in and your server knows what they have access to.

As an experiment you might try signing up for Netflix directly though the iOS app and then see what happens when you try to modify your subscription on their site. Granted, Netflix may have worked out some deal with Apple to do more than the typical developer, but I think it could be revealing and informative to see how a big player is handling the situation.

Hi, Geat tutorial. It really helped me and came at the right time as I was already struggling with Auto-Renewal Subscriptions. I have one question though. To get my code to work, I had set productIDPrefix to “” . I am not the only one as I have seen this on some forums online with other kinds of IAP. Do you have any hint as to where does that come from ?

This is a great tutorial but do you have something similar in objective-c as I am not using swift.

Certainly an interesting tutorial, however I have one problem with it (and many other recent RW tutorials).

There’s so much “overhead” (custom classes/ functions supplied in the starter project), that you never actually learn the underlaying technologies and frameworks we set out to explore.

In its essence, it’s like you are teaching us how to use a completely custom framework built on top of StoreKit, which is unique to this project and not directly transferrable to a separate app.

If I were to set out and create an app with auto-renewing subscriptions, I would not be able to do so after only reading this tutorial. As a matter of facts, I have spent several days reading multiple different tutorials just trying to figure out how to determine whether there is a currently active subscription. In this project, we’re just told to insert this code to guard for non-subscribers accessing locked content.

I realize the purpose of these starter projects is to make the articles shorter and easier to complete, but I would rather spend a little more time reading a more in-depth walkthrough of how to use the frameworks without the overhead of a starter project that is never explained.

Just my suggestion for future tutorials!

Hi,
Great tutorial. I have few questions

  1. Why SKPaymentTransactionStatePurchased called many times? Sometimes without enter the password of apple id.
  2. When I click “Ok” in “Do you want to modify your subscription to some other product”, it always returns an error “Cannot connect to iTunes store code 0”.
  3. How to clean the previous transactions? It always comes when I restore or purchase any products.

@cwagdev The link in the following text in your tutorial appears to be broken.

“Sam Davies does a stellar job explaining a lot of these details in In-App Purchase Video Tutorial: Part 4 Receipts.”

This is likely due to the way that you’ve configured your purchase items in iTunes Connect, if you did not provide any sort of prefix to their names then you do not need one. We are suggesting the use of prefixes to clearly namespace items if you happen to have multiple apps on your developer account.

Sorry, Joel. We do not write Objective-C tutorials on the site anymore (unless required for some technical reason)

Thanks for the feedback Alek, it’s a tough balance between keeping the tutorials consumable for a wide audience and getting the main point across. We strive to have the reader do as much of the work that is relevant as possible.

You are right that this tutorial had a pretty hefty stater project, unfortunately a massive portion of the writing was taken up by working through iTunes Connect. This topic may be a candidate for a video series or even a book of its own that covers all aspects of in app purchases. I hope that we were able to provide enough to get you going on your project.

Hey Daljeet

  1. Is it possible that you’re not marking your transactions as completed? The system will alert you of them over and over at each app launch until you do, to ensure that no payment was missed by you.

  2. I hate to say it, but I’d try again later. It’s possible the iTunes Connect sandbox is having issues. It is VERY finicky. During the editing of this tutorial, one of the editors literally had to wait a week to do any work as the sandbox was down for an entire week, very frustrating.

  3. For renewable subscriptions the previous transactions are always on the receipt, this is a feature of the app store.

Thanks for pointing that out brise, I’ve updated the link in the tutorial.

https://videos.raywenderlich.com/courses/31-in-app-purchase/lessons/4

Auto-renewble subsriptions: Is it working on iOS8 or its only for iOS10?

Having working code is incredibly useful - as the user is able to target an area to extend their knowledge. The balance IMO is fantastic.

(I have just started this tutorial - and a couple of thoughts)

+) iTunes connect : Mention to ignore the ‘Missing Metadata’ the moment it appears. This avoid self-FUD.

+) I saw a repeat notification name below - and will revisit after the completing the tutorial to see if this is deliberate (if deliberate, please ignore)

static let purchaseSuccessfulNotification = Notification.Name(“SubscriptionServiceRestoreSuccessfulNotification”)

AJ

How do you know if it is still in free trial mode and if it is expired ? Does it automatically start billing them or do they have to purchase again ? Also, how do you keep track of the free trial do you need to call purchase every time your application starts or something ?

@aston_calvin, as far as I can tell, there’s no requirement of iOS 10.

@joelparker, the trial period is handled by Apple. When the trial ends the user’s paid subscription starts, which will be on the receipt. You are responsible for gating your content on this condition. The receipt should tell you when the trial period will expire and you can treat it like a shortened paid subscription period.