Kodeco Forums

In-App Purchase Tutorial: Getting Started

Learn how to grow app revenue in this in-app purchase tutorial by allowing users to purchase or unlock content or features. Updated for iOS 9 and Swift 2.


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/1244-in-app-purchase-tutorial-getting-started

Just to add, in your InAppRageDemo Final IAPHelper.swift on like 161 you get a compile error in iOS 9.3 and need to change this code:

if transaction.error.code != SKErrorPaymentCancelled {

to this, where they have changed the SDK of the SKErrorCode:

if transaction.error!.code != SKErrorCode.PaymentCancelled.rawValue {

Other than that, great tutorial thanks.

(http://stackoverflow.com/questions/36156724/unresolved-identifier-skerrorpaymentcancelled)

Well it would be nice if you can integrate also consumable products for ex: adding some coins to label 
 Tnx

Great guide for Swift but was wondering if there was any way to get this new Xcode 7.3 iOS 9 guide with Objective-C files. I’m sure I can’t be the only one with old projects that needs an updated IAP :slight_smile:
Thanks

Hello,

I found that sandbox purchases work, but when I sign into my personal account to make a purchase, I get the error:

Error Domain=SKErrorDomain Code=0 “Cannot connect to iTunes Store” UserInfo={NSLocalizedDescription=Cannot connect to iTunes Store

I found that restarting my iPhone corrects this behavior. Do you know if signing in and out of the iTunes app store breaks connectivity to the iTunes store?

The original tutorial from a few years ago covers how to do this in Obj-c. Even though it’s a few years old, the instructions are still valid. I used them to create the IAP for 2 of my apps.

App crashes when I click on Buy button . I have followed all the steps mentioned in the tutorial without any mistake. Same error in the final downloaded code.
Please help me resolve the issue.
[Rage.ProductCell ProductCell.buyButtonTapped(:):]: unrecognized selector sent to instance 0x162b1c00
2016-04-27 16:04:41.336 Rage[534:112914] *** Terminating app due to uncaught exception ‘NSInvalidArgumentException’, reason: '-[Rage.ProductCell ProductCell.buyButtonTapped(
:):]: unrecognized selector sent to instance 0x162b1c00’
*** First throw call stack:
(0x2202010b 0x217c6e17 0x22025925 0x22023559 0x21f53c08 0x261946cd 0x26194659 0x2617c64f 0x26193fb5 0x2614e275 0x2618ce21 0x2618c5d3 0x2615d2f9 0x2615b98b 0x21fe368f 0x21fe327d 0x21fe15eb 0x21f34bf9 0x21f349e5 0x23180ac9 0x261c4ba1 0xd7f4c 0x21be3873)
libc++abi.dylib: terminating with uncaught exception of type NSException

I would check your outlets and actions in Interface Builder. Select the ViewController that contains your button in the UINavigator. Then go to the the connections inspector in the Utility Pane. Check that the connections are hooked up properly and delete any that shouldn’t be there. Hovering over the connections highlights their associated views and can be helpful in sorting it out. I hope this helps!

Is it possible to A) use this method to purchase an Audio track and then play it with in the app? Down load it almost as a local bundle file? B) can the above Swift code be used in an existing objective-c app?

Hi,

I am working on iOS application with media content, purchased by $1 per any item. I want to give for every new user discount: first any five items by $0 per item. How to do this?

This whole process is extremely frustrating. The in app purchase won’t show up in the app which may be related to not having uploaded a screenshot for the in app purchase (of which there is no mentioning in this tutorial). So I did that and it still won’t show up. The status in the list of In-AppPurchases in iTunes Connect says: “Ready to submit.” with a yellow light. I thought I had submitted it already, what should I do?

It seems like the product identifier no longer contains the bundle ID as a prefix. So in the example of this tutorial I had to use “GirlfriendOfDrummerRage” and not “com.mybundle.Rage.GirlfriendOfDrummer”
Is this a new Apple naming scheme or did I miss out on something ?

I had the same issue, then I went in “RageProducts.swift” and in the RageProducts struct, I cleared the Prefix (private static let Prefix = “”)
and that solved the issue. Hope that’ll help you

Your tutorial helped me a lot - thanks for it!
However, this whole process has been incredibly frustrating. I’ve followed your exact steps (and I’m testing it on a real device, not the Simulator). However, after my first purchase (my app offers 3 options), the paymentQueue_updatedTransactions function is being called repeatedly, for no reason. For example, if the [transactions] array has 3 items, the whole function is being called three times. Anyone know why this could be happening?

Great tutorial, thanks.
Two questions:

1.) Is there a way to sort the order of the products that come back from Apple? Do they show up in the app in the same order the are listed in iTunes Connect?

2.) Is there a way to fire this code before this Table View is loaded? My IAP page is a tab, so the user selects the tab, and then it takes a few seconds for the products to load. Is there a way to get this to run before the person loads this view? So that by the time they select the tab the products are already there?

Thanks again!

Thanks for the great tutorial. I had same issue of not showing up the products listing. We don’t need to add prefix in RageProducts class when defining the in app purchase product id. Once again thank you for the tutorial.

In RageProducts.swift you mention the line:
private static let productIdentifiers: Set = [RageProducts.GirlfriendOfDrummerRage]
but in the file created by Apple the line is:
private static let productIdentifiers: Set = [RageProducts.GirlfriendOfDrummerRage]

Then in the file IAPHelper.swift when I add the line:
private let productIdentifiers: Set,
I get an error "Reference to generic type ‘Set’ requires argument. I am getting numerous errors when entering lines
into the IAPHelper file.

Error: the line created by Apple is:

private static let productIdentifiers: Set = [RageProducts.GirlfriendOfDrummerRage]

Error:
Cannot cut and paste and then delete part of a line. The line produced by Apple is:

private static let productionIdentifiers: Set = [RageProducts.GirlFriendOfDrummerRage]

Sorry for the errors in submitting this. I am new to a forum.

Your tutorial help me a lot.I gone through the In-App purchase tutorial.Everuthing is ok according to my project i want to impement the buy using UIbutton. if i add this RageProducts.store.buyProduct(product)
inside a Uibutton action i am not getting Skproduct from the product list
Wating for your reply thank you
!