In-app purchase tutorial

Hi everyone. Through the process of making my first iOS app with in-app purchases, I made a little tutorial with a sample project. Hope the link below works for you and that you find the walkthrough beneficial

Credit must be given to Jason King for compiling StoreKit in iOSKit and to Jeremie Leroy for his personalized help with me

Nice tutorial! You mention some modifications had to be made to the StoreKit stuff. Please submit a pull request on Github with the changes so that the project is up to date. If you need help with that send me a private message and I can assist.

Good suggestion. Best to have one primary StoreKit (yours). I’ll work on it today. I didn’t really keep a log of what was changed, but I think I can run the project with a copy of the current iOSKit and cross reference with the changes. I might need some help with submitting a pull request and will reach out if needed. Haven’t used GitHub other than downloading projects

iOSKit should be updated to reflect the necessary changes for Ryan’s example project. If anything is missing or doesn’t work, please send me a PM so I can address it.

Confirmed! I downloaded the updated iOSKit from Jason’s GitHub, replaced StoreKit in my sample project, and it ran great

Many thanks to the Xojo team for posting the tutorial in a blog post. I have the link to the post below, which includes the sample project I had in the DropBox link above. As a result, I removed the items in DropBox just to keep it all consistent


Great job with the tutorial. I downloaded your sample project, changed App Name, bundleID and inAppPurchaseID’s to my app info.
When I run the project in Simulator the modal purchase view shows my inAppPurchase info but, as you said, can’t actually buy it in the Simulator…
Build the app, put it on an iOS device and the modal purchase view shows for about 5-10 seconds then the app goes away (back to home screen). The app still shows in the running apps view with a blank thumbnail and when I tap it the app launches with the main view.
One thing you did not mention that I am doing is code signing when the app is built. Under iOS Code Signing I selected my Team from the popup menu. I guess I should try without code signing.
Anybody have any ideas?

Huh. Yep I see that too. Just tried the sample IAP app in the example. It runs fine in simulator (clicking Buy Premium from the home view opens the modal and pulls in the premium data) but when copied to the phone, it opens the modal with no IAP data shown and then crashes a few seconds later

Question. Were you attempting this with my sample data for the project, or did you create your own new app and IAP product in ITC? Wondering if it’s acting funny because of the dummy product I have in ITC. I did not attempt to make a new product and IAP product

I have my own product and IAP defined in ITC.

Weird. I’m hoping nothing big has recently changed. I haven’t gotten around to making another IAP app yet.

What version of Xojo and Xcode are you using? I have 2019r3 and 10.1. Not sure if that makes any difference. Xcode 10 still seems to be fine with 2019r3 per the system requirements page

Has anyone else, recently done an IAP using the tutorial?

I am also using Xojo 2019r3 and Xcode 10.1.

Hi CT. Have you had any success with the IAP? IÂ’ve been busy working on another project and havenÂ’t had time to explore IAP any further. Been wanting to implement in another project thatÂ’s gotten held up

I saw an unrelated post from a couple weeks ago that there might be some incompatibilities with 19r3 and Jérémie’s iOSDesignExtensions, so wondering if that’s the reason for IAP not working on the device, specifically the modal perhaps. Think that’s what is being used from the extensions

@Jeremie Leroy have you made any updates to iOSDesignExtensions for 2019r3 lately?

I also saw that post. I have also tried using a non-modal view so not reliant on iOSDesignExtensions. So, no progress. I will be giving my Xojo.Connect speech without a solution to this issue.

[quote=475389:@C T Baumgartner]
Build the app, put it on an iOS device and the modal purchase view shows for about 5-10 seconds then the app goes away (back to home screen). The app still shows in the running apps view with a blank thumbnail and when I tap it the app launches with the main view.[/quote]
This actually means that the app crashed. You should be able to extract the crash logs from your iPhone using Xcode.

  • Connect your iPhone to your Mac
  • Open Xcode
  • Go to Window > Devices and Simulators
  • View Device logs

You can also send the crash log from the iPhone:

  1. Navigate to your device Settings > Privacy > Analytics > Analytics Data.
  2. Scroll through this list to find your App events. The list is alphabetical.
  3. Tap one of these events.
  4. Tap the share icon at the top right.
  5. Email it to yourself

anyway, I can have a look at your code to help troubleshoot the problem in Nashville

Hi CT and Jeremie. I believe there actually is an incompatibility with Xojo 2019r3 (and r3.1 probably) and the IAP sample I have in the tutorial. When I built the test IAP sample app in 19r3 and used Xcode to transfer to the device, opening the Buy Now modal view does crash within about 2-3 seconds. Does not crash in Simulator in 19r3. I checked the crash log as Jeremie suggested in Xcode, but did not see anything. On the phone, I did find the crash report but am not familiar with how to find what is going on

However, then I tried to build with 2019 r2, which is the Xojo version I used to build the tutorial app and my first IAP app for the App Store. Built the IAP Sample app, transferred to the device, and it worked with no crashes! I would suggest using 2019 r2 to build your app with IAP if possible. See if this works

Maybe we can get with Jeremie at Xojo.Connect to see what’s going on with 19r3 and the IAP helper methods he helped me with for the tutorial sample

I get that too in one of my apps. It’s a stackoverflow exception.
I haven’t solved it yet but hope to do it soon as building with Xojo 2019r3 will be mandatory to publish on the AppStore starting in April 2020.

Good to know it’s not just us or the sample I made up for others to use. If you happen to discover the fix, would you mind if we worked together so I can get the sample updated on the Xojo blog post? April is just around the corner, but at least we can build an IAP app before then and have it on the store using 2019r2

Of course we can work together. I really hope to get this fixed ASAP as I need to release multiple updates of my apps in April

I’ll keep this thread updated when I have a solution

That’s great Jeremie! Thank you! You’re truly an inspiration to us all. And to speak on behalf of everyone else, I (we) appreciate all you do in the iOS channel

Thanks to Jeremie’s instructions for reading the logs on my iPad here is what I found and my fix for the crash problem.
Crash log says, in part:
“+[UIView setAnimationsEnabled:] being called from a background thread.Performing any operation from a background thread on UIView is not supported”
“-setBackgroundColor: sent to <XOJCustomTableCell:”
This let me to believe the crash was caused by the way the method was called to write the in app purchase products list to my iOSTable.
My fix was to add to following new method which is called by the InAppPurchaseHelper completionHandler to just save the parameters to properties of the view and set a flag

LoadProducts (success as Boolean, products as Foundation.NSArray) pSuccess=success pProducts=products pboolLoad=true
I renamed the existing LoadProducts method to LoadProductsNow(success as Boolean, products as Foundation.NSArray)
Then I added a timer to the view to check the flag and call LoadProductsNow when pboolLoad was true.
Timer1.Action code is simple

[code]if pboolLoad then
end if[code]

I have checked this on both my project which doesn’t use a modal view and on Ryan’s example project which uses a modal view.