In-app purchase tutorial

Hi Ryan, awesome, thank you! I don’t know why but I had to delete all my in-app purchases in AppStore Connect and create them again. Now it works! Thanks a lot!

1 Like

Jason,

I was looking at the notification classes in iosKit. I don’t see how they work as there are no declares.
Likely I’m missing something really basic (no pun intended).

-Bob Gordon

The notifications from iOSKit are code notifications to let one class communicate with another.
Example:
A user pushes a button that starts a thread. When the thread finishes it notifies the view to update the contents.

This has nothing to do with Notifications the way Apple documents it.

1 Like

Testing an IAP in sandbox, I’m using this code from @Ryan_Hartz IAP tutorial to buy the IAP:

Helper = StoreKit.InAppPurchaseHelper.GetInstance

For Each p As StoreKit.SKProduct In products
  
  if p.productIdentifier = productID then
    
    Helper.BuyProduct(p)
    
    Return
    
  end if
Next

'transaction succesful.  make property set to true
'Using Jason's StoreKit module, if the purchase is successful, the following property will be set to true
dim productPurchased as Boolean = Foundation.NSUserDefaults.StandardUserDefaults.BoolForKey(productID)

'add is successful purchase then set ActivatePremium = True
ActivatePremium = productPurchased

It always returns ActivatePremium = False though. It seems the code does not wait for the user to enter the password but just continues running and setting the ActivatePremium. Does anybody have the same problem?

Is an asynchronous call.

StoreKit.InAppPurchaseHelper has a RemovedTransactions event you can add a handler for to get information on the payment process.

1 Like

So easy, yet so effective! Thank you, Jeremie.

1 Like

Thanks for the great tutorial, I am trying to get my first in-app purchase going. Got so far as copied the IOSKit folder (Modules) and the IOSExtensions into my project. Next step is confusing… (to me):

“The ModalPurchaseView from the sample project can be copied to your project and used to cover the purchase/restore functions. Be sure to change the pieces in the code that points to your in-app purchase product, such as com.mycompany.myapp.myIAPproduct”

I assume you talk about the sample project of the IOSDesignExtensions, the only Modal View in the Views folder is the “vModal”, and there doesn’t seem to be a code to change to fit my products.

I need some help to proceed… Thanks a lot!

There is a sample project connected with the blog post. Scroll to the bottom and there is a link.

1 Like

Thanks Jason! Life saver… :grin:

Has anyone done an IAP with the latest Xojo R2.1?

I haven’t yet.

1 Like

I’m currently working on it and plan to test it end of next week. Will keep you posted.

Thanks Christoph, have you experienced the buy screen coming up but the App crashing?

Yes, but that’s only in the simulator. It doesn’t crash on the real device.

1 Like

Hi Martin! I have completed the code for an IAP (non-consumable) with the latest Xojo and @Jason_King iOSKit/StoreKit. I don’t have any issues in Sandbox, works like a charm. Haven’t tested it on TestFlight or in the AppStore yet.

Awesome Christoph, so now I need to know what you have done differently to my attempt that crashes. Interesting I submitted a version to the App Store and they accepted it but when I test it, it crashes so I haven’t released it.

How can I get an example of the crucial parts of your code and can I get your copy of ioskit to cross check?
Thanks
Martin

I will prepare a sample project and send it your way tonight or early tomorrow morning.

Maybe you can share with community :wink:

1 Like

I am sorry, took me a lot longer than expected. The display of my MacBook passed out and it’s now with Apple for the next three weeks so I had to find a replacement. Thank God for our awesome neighbors.

This is the code I am using. It crashes in the simulator but it works on a device. Most (if not all) of the code and comments are from @Ryan_Hartz IAP tutorial. Just reshuffled some of the stuff. The sample project also has some of @Jason_King and @Jeremie_L extensions.

This is what you have to do to make it work:

  1. Make sure to replace the values in the productID with your company name, app name and IAP name everywhere in the code.

com.ReplaceWithCompanyName.ReplaceWithAppName.ReplaceWithIAPName

  1. The same values have to show in the bundle identifier in the iOS settings.

com.ReplaceWithCompanyName.ReplaceWithAppName

  1. Make sure to activate In App Purchase in the iOS build settings. It is activated in the sample project but if you copy the code to your project, it might not be.

https://www.amazon.de/clouddrive/share/R22IyELIQOVQrWm4gDBHmRRALQFyUoaml4yw3UuOlct

4 Likes

@Christoph_Emrich Thank you for sharing!