|
1 | 1 | # InApp purchasing implementation for Apple (iOS/RoboVM) |
2 | 2 |
|
3 | | -### Dependencies |
| 3 | +This module provides two `PurchaseManager` implementations for iOS: |
| 4 | + |
| 5 | +| Implementation | API | Minimum iOS version | |
| 6 | +|---|---|---| |
| 7 | +| `PurchaseManageriOSApple` | StoreKit 1 | iOS 7+ | |
| 8 | +| `PurchaseManageriOSApple2` | StoreKit 2 | iOS 15+ | |
| 9 | + |
| 10 | +## Choosing between StoreKit 1 and StoreKit 2 |
| 11 | + |
| 12 | +**StoreKit 2** (`PurchaseManageriOSApple2`) is the recommended implementation for new projects. It uses Apple's modern StoreKit 2 Swift-based API (via [RoboVM StoreKit 2 bindings](https://github.com/MobiVM/robovm-cocoatouch-swift)) and provides: |
| 13 | + |
| 14 | +* Improved subscription handling, including eligibility checks for introductory offers via `isEligibleForIntroOffer()` |
| 15 | +* A modern async-based API under the hood |
| 16 | + |
| 17 | +**StoreKit 1** (`PurchaseManageriOSApple`) should be used if your app needs to support iOS versions below 15. |
| 18 | + |
| 19 | +If your app targets a range of iOS versions, you can select the implementation at runtime based on the device's iOS version (see [Instantiation](#instantiation) below). |
| 20 | + |
| 21 | +## Dependencies |
4 | 22 |
|
5 | 23 | implementation "com.badlogicgames.gdxpay:gdx-pay-iosrobovm-apple:$gdxPayVersion" |
6 | 24 |
|
7 | | -### Instantiation |
| 25 | +This single dependency includes both `PurchaseManageriOSApple` (StoreKit 1) and `PurchaseManageriOSApple2` (StoreKit 2). |
| 26 | + |
| 27 | +The StoreKit 2 implementation depends on the RoboVM StoreKit 2 bindings, which are included as a transitive dependency: |
| 28 | + |
| 29 | + com.mobidevelop.robovm:robopods-swift-storekit2 |
| 30 | + |
| 31 | +If your app only uses StoreKit 1 and you want to exclude the StoreKit 2 transitive dependency, you can do so in your Gradle configuration: |
| 32 | + |
| 33 | + implementation("com.badlogicgames.gdxpay:gdx-pay-iosrobovm-apple:$gdxPayVersion") { |
| 34 | + exclude group: 'com.mobidevelop.robovm', module: 'robopods-swift-storekit2' |
| 35 | + } |
| 36 | + |
| 37 | +### Note for Kotlin users |
| 38 | + |
| 39 | +Both `PurchaseManageriOSApple` and `PurchaseManageriOSApple2` work with Java and Kotlin without any special configuration. All async operations and callbacks are handled internally by the `PurchaseManager` implementation — you interact with it through the standard `PurchaseObserver` interface regardless of your language. |
| 40 | + |
| 41 | +Separately, there is also a Kotlin coroutine wrapper available (`com.mobidevelop.robovm:robopods-swift-storekit2-kt`) for projects that want to use the StoreKit 2 API directly without gdx-pay. This is **not** needed when using gdx-pay. |
| 42 | + |
| 43 | +## Instantiation |
| 44 | + |
| 45 | +### Using StoreKit 1 only |
8 | 46 |
|
9 | 47 | Add this to your `IOSLauncher`: |
10 | 48 |
|
11 | 49 | game.purchaseManager = new PurchaseManageriOSApple(); |
12 | 50 |
|
| 51 | +### Using StoreKit 2 only |
| 52 | + |
| 53 | +Add this to your `IOSLauncher`: |
| 54 | + |
| 55 | + game.purchaseManager = new PurchaseManageriOSApple2(); |
| 56 | + |
| 57 | +### Selecting at runtime based on iOS version |
| 58 | + |
| 59 | +If your app supports both older and newer iOS versions, you can choose the implementation at runtime: |
| 60 | + |
| 61 | + import org.robovm.apple.foundation.Foundation; |
| 62 | + |
| 63 | + if (Foundation.getMajorSystemVersion() >= 15) { |
| 64 | + game.purchaseManager = new PurchaseManageriOSApple2(); |
| 65 | + } else { |
| 66 | + game.purchaseManager = new PurchaseManageriOSApple(); |
| 67 | + } |
| 68 | + |
13 | 69 | ## Testing |
14 | 70 | Next to other ways, I find the easiest way to test the IAP the following: |
15 | 71 |
|
|
0 commit comments