Kodeco Forums

Video Tutorial: In-App Purchase Part 2: Making a Purchase

This video will teach you how to integrate IAP into your app and accept purchases. You'll use your sandbox account to "make" a purchase to remove the ads in the GreenGrocer app.


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/4158-in-app-purchase/lessons/3

Thanks for the tutorial. Apple has removed SKErrorPaymentCancelled from the SDK as of iOS 9.3. This tutorial would need to handle using SKErrorCode.PaymentCancelled instead else Xcode would flag error.

1 Like

Thanks for pointing that out. We’ll be sure to include it when we update the video.

sam

Just a heads up for others - you’ll need to use SKErrorCode.PaymentCancelled.rawValue to get an Int type you can compare with.

1 Like

Thank you so much :]

1 Like

Hello. Please is there a tutorial where I can learn more details about Dependency Injection in Swift? How to use it and When to use it.

I also want to ask, what if my products are items that have to be downloaded from the internet, how do I check for matching product IDs since I can’t create an enum for product I have to fetch from the internet like was done in the Demo project

Hi @tobitech

If by “downloaded from the internet” you mean that you dynamically want to change the IAP products after the app has launched then, you can’t. You have to define your IAPs ahead of time.

One possible solution would be to allow the user to purchase expendable credits—which they could then exchange for something from the dynamic products list. It would then be up to you to track what products they had purchased, and if you so wish, persist that across devices. iCloud might be a good solution for this.

Hope that helps

sam

Hi Sam, in this part 3, I don’t see anywhere in the Demo code where you initialised IAPHelper as usual with a set of identifiers, you just made requests in the updateIAPHelper() function. When I followed the pattern, my payment doesn’t go through, aren’t we supposed to initialise the IAPHelper with a Set of product Identifiers as you did in previous parts?

I have an app in development which uses a navigation controller and table view controller for the purchase view presented to users. My app requires the IAP be purchased before it does anything useful. Upon opening the app it checks if the user has purchased the auto renewing subscription. If it is purchased the app seques to the main functionality of the app. This works fine. If they need to purchase the subscription the app segues to a purchase view (the table view controller with the navigation controller). Once the purchase is made the customer can use a Left Bar Button item to segue to the main functionality of the app. The problem is that almos all of the views linked to from the main view contain UINavigation items which are hidden by the Navigation controller. Is there a way to have IAP without Navigation Controllers and table views?

Hi @gofish

I might be misunderstanding your question, but there’s no reason that IAP requires nav controllers or table views. You can build any UI that you want into IAP. The StoreKit framework provides the machinery to accept IAPs, but allows you to provide whatever UI you would like.

Apologies if I misunderstood your question.

sam

I’m sure its me that doesn’t understand IAP enough. My problem is that when I remove the Navigation Controller from the app I built based on your tutorial, the sandboxed purchase stops working.

Thanks for your answer I will try to figure this out.

1 Like

First: Thanks Sam for this great tutorial! I managed setting up IAP for my app w/o any complications so I got the products Set successfully from the start :slight_smile:

Now I wanted to go further and tried to use the example code w/ XCode 9 and Swift 4 for iOS 11. Result were many minor SDK naming changes as well as some other stuff (NSDateFormatter, Date conversion etc.).

The transition seems to become tedious (20+ fixes needed). So I wonder if there’s an update of the tutorial is in the making - what are the current plans upgrading this tutorial?

Best wishes,

Karsten

Hi @gresch,

I’m really happy that you managed to use this tutorial to get IAP working in your app. IAP is by no means easy, but is incredibly important to app developers who want to make some money.

I’m sorry that the code doesn’t work—it is getting a bit long in the tooth, and is due an update. I don’t know the schedule of such an update, but @jessycatterwaul is in charge, and might be able to shed some light on it.

Best of luck with your app

sam

1 Like

Hi Sam,

thanks very much for your reply, very appreciated!

After fixing a first bunch of compile issue, I found out there were more to fix (Data object → UUID + plist stuff, serialization) so I give up and try to just follow your videos and adjust the example code to my needs, step by step.

For other users I guess, an update should be quite useful as IAP are a practically relevant topic…

Best wishes,

Karsten

1 Like