In-App Purchases: Non-Renewing Subscriptions Tutorial

Learn to offer access to time-limited content to users and monetize your app using In-App Purchases in this Non-Renewing Subscriptions Tutorial. By Owen L Brown.

Leave a rating/review
Save for later
Share
You are currently viewing page 2 of 4 of this article. Click here to view the first page.

To Do List

  1. Get a copy of Parse Server
  2. Connect a new Heroku app to the Parse Server
  3. Setup the app to use MongoLab for the server database
  4. Connect the InsomniOwl app to Heroku
  5. Add new products to iTunes Connect
  6. Setup a Sandbox Tester
  7. Add new products to InsomniOwl app
  8. Expiration date handling
  9. Display the content
  10. Final touches

Now that you know where you are going, time to get to it!

Parse Server & Heroku

First, you’ll need to set up an app in Heroku for this tutorial. To do this, do the following:

Non-Renewing Subscriptions

Non-Renewing Subscriptions

Non-Renewing Subscriptions

Note: Enter random characters in the APP_ID and MASTER_KEY fields. Keep these secret as it prevents others from accessing your app backend. You’ll use them shortly in the iOS app.

Non-Renewing Subscriptions

Non-Renewing Subscriptions

Non-Renewing Subscriptions

  1. Head over to the Parse Server GitHub.
  2. Click the Fork button at the top right and select one of your existing repositories. This will create a copy of the Parse Server example that you can integrate with Heroku.
  3. Scroll down the forked repository and click the Deploy to Heroku button. This will open the Heroku website and begin the Parse Server integration.
  4. Create a new Heroku account or login to an existing one.
  5. A new Parse Server Example app will appear. Enter an app name.
  6. The MongoLab Add-On is free, but you may need to enter credit card information to use it. Finish filling out the remaining fields. Leave the PARSE_MOUNT value at the default /parse location. Replace the yourappname section in the SERVER_URL field with, you guessed it, your app name. But be sure to keep the .herokuapp.com/parse part.
  7. Click Deploy and wait until the deployment process completes. The automatic process is copying over the Parse SDK server to Heroku and setting up the variables needed for access.
  8. Once deployment is successful, click on Manage App. Then click Settings to view the application variables.
  9. Now click the Reveal Config Vars button to display the configuration variables created during deployment. There are 3 variables to copy to the Xcode project: APP_ID, MASTER_KEY, and SERVER_URL. Take note of them!

Now that you’ve finished the Heroku and the Parse Server setup, open the Xcode starter project. Open AppDelegate.swift and in application(_:didFinishLaunchingWithOptions:) replace the applicationId, clientKey and server property values with your Heroku’s configuration values.

let configuration = ParseClientConfiguration {
  $0.applicationId = "com.razeware.InsomniOwl.somethingRandomHere"
  $0.clientKey = "myMasterKeyKeepItSecret"
  $0.server = "https://insomniowl.herokuapp.com/parse"
}

Note: You must prefix the server property with https, NOT http. Otherwise, the app will not access the Parse Server and the Console will display an error: The resource could not be loaded because the App Transport Security policy requires the use of a secure connection.

Build and run. When the app launches for the first time, you need to create a new account before the displaying the products list.

Non-Renewing Subscriptions

Enter a username and password to create a new account and select Sign Up. When you’re done, you should see something like this:

Who stole the goods!

Non-Renewing Subscriptions

Wait a second, where are the cool Owl images? Well…they’re not in your iTunes Connect account yet. Head over there now!

iTunes Connect

Add In-App Purchase Items

You must register In-App purchased products into iTunes Connect before they will appear in an app. Do the following:

  1. Log onto iTunes Connect
  2. Click My Apps
  3. Add a new iOS app for this project.
  4. Select the new app and click on Features.
  5. Click In-App Purchases and then the + button.

Non-Renewing Subscriptions

To provide the app some purchasing variety, add the following Consumable, Non-Consumable and Non-Renewing Subscriptions. For the tutorial, only enter the name, product ID, and a price. The product ID should be your reverse website, app name and product name. For example: com.yoursite.yourappname.3monthsOfRandom. The last part (ex. 3monthsOfRandom) for each item must match perfectly as listed below in order for the tutorial app to grab the correct Owl image.
Also, be sure to check the Cleared for Sale box or the item won’t display in the app.
Enter the following items and use the specified Product ID suffix:

  • Non-Renewing Subscription: 3monthsOfRandom
  • Non-Renewing Subscription: 6monthsOfRandom
  • Non-Consumable: CarefreeOwl
  • Non-Consumable: CouchOwl
  • Non-Consumable: CryingOwl
  • Non-Consumable: GoodJobOwl
  • Non-Consumable: GoodNightOwl
  • Non-Consumable: InLoveOwl
  • Non-Consumable: LonelyOwl
  • Non-Consumable: NightOwl
  • Non-Consumable: ShyOwl
  • Consumable: RandomOwls

Note: It is important that you specify the duration of any subscription-based IAP, and the most common way to do this is in the display name or description. There’s a good chance Apple will reject the app if it fails to clearly state the duration of any subscription.

When it is all said and done, you should see the following:

Non-Renewing Subscriptions

It’s important to get the Product IDs specified correctly. The Product IDs prefix must match your apps Bundle Identifier. The suffix uniquely describes the product. Ex: com.yourwebsite.yourappname.3monthsOfRandom.

If you are using your own Bundle Identifier in the app, you’ll need to update the Product IDs in the starter project. Open OwlProducts.swift and update productIDsNonConsumables to match the Product IDs you setup in iTunes Connect.

static let productIDsNonConsumables: Set<ProductIdentifier> = [
  "com.back40.InsomniOwl.CarefreeOwl",
  "com.back40.InsomniOwl.GoodJobOwl",
  "com.back40.InsomniOwl.CouchOwl",
  "com.back40.InsomniOwl.NightOwl",
  "com.back40.InsomniOwl.LonelyOwl",
  "com.back40.InsomniOwl.ShyOwl",
  "com.back40.InsomniOwl.CryingOwl",
  "com.back40.InsomniOwl.GoodNightOwl",
  "com.back40.InsomniOwl.InLoveOwl"
]

Sandbox Surprises

Ok, you have the goods, but something is still missing. A sandbox user!
Testing In-App Purchases requires at least one sandbox user. This lets you make purchases in the app without actually paying the cash. Add one now:

  1. In iTunes Connect, click Users and Roles
  2. Click Sandbox Testers
  3. Add a tester with an email address that is not used as an Apple ID.

You must always test In-App purchases on an actual device. Sorry Mr. Simulator, you’re out of job.
Open Settings on your iOS device and logout of iTunes & App Store. Do NOT login as your sandbox user email. Doing so will make it an Apple ID and the email will no longer be valid for sandbox testing.

Now you have the goods to sell and a sandbox tester, run the app again. You should now see the list of items you entered. But why are only the non-consumables showing? Good question. It is because the starter app doesn’t support the other types yet. You’ll be fixing that shortly.

Non-Consumables

Non-Renewing Subscriptions

You have to check out at least one of the owl images. So go ahead and make a purchase. Its on me!
When it prompts you to sign into iTunes Store, be sure to use a sandbox user.

Good Job Mate!

Non-Renewing Subscriptions

Non-consumable items show up in the app and are ready for sale. Now you’re ready to begin implementing non-renewing subscriptions!

Owen L Brown

Contributors

Owen L Brown

Author

Darren Ferguson

Tech Editor

Essan Parto

Final Pass Editor

Andy Obusek

Team Lead

Over 300 content creators. Join our team.