Skip to main content

Migrating to 11.0.0

Migrating to 11.0.0

Version 11.0.0 is centered around implementing iOS Storekit 2.

I've worked hard on keeping backward compatibility. However there are things that don't translate directly to previous versions.

API changes

These are changes that you'd need to make even if you are not going to use Storekit 2:

  • requestPurchaseWithOfferIOS and requestPurchaseWithQuantityIOS are now part of requestPurchase by simply passing the appropriate parameters

  • Methods that are exclusive to a platform, have been moved to nested objects IapAndroid, IapAmazon, IapIos, IapIosSk2. So for example validateReceiptAndroid is now available as:

import {IapAndroid} from 'react-native-iap'
...
IapAndroid.validateReceiptAndroid(...)

In particular the following methods are avaiable only on Sk2 : sync,isEligibleForIntroOffer, subscriptionStatus, currentEntitlement,latestTransaction should be called as this:

import {IapIosSk2} from 'react-native-iap'
...
IapIosSk2.isEligibleForIntroOffer(...)

This allows for greater flexibility to use methods that are specific to a platform but the others don't offer. All the other common methods are still called in the same way as before

Using Storekit 2

note

Storekit 2 (Sk2) requires iOS 15 as a minimum.

If your app supports only iOS 15 and above (see below how to determine that). And you want to use storekit 2 new features such as subscription groups then use STOREKIT2_MODE during setup (see below)

If your app supports older iOS versions, you'll have two options 1) STOREKIT1_MODE will let you use the legacy code to all interactions with the library (i.e. no changes, this is the default). And 2) STOREKIT_HYBRID_MODE Will use Sk2 on devices that support it. The library will use the old implementation (Storekit 1) as a default on devices with older versions of iOS

danger

Please consider the edgecases of using both (See differences below).

How do I know what's the minimum version of iOS my app supports?

Open ios/Podfile file and look for the following line:

platform :ios, '15.0'

How do I enable the use of Storekit 2

Call setup before you initialize your connection as follows:

import {setup} from 'react-native-iap'
...
setup({storekitMode:'___Selected Mode___'})// See above for available options
await initConnection()
...

Buying items for user

When calling requestPurchase: The name of this parameter has changed to match the new API applicationUsername -> appAccountToken

No longer available in Sk2:

  • Purchase promoted product. I haven't found the equivalent of promoted product purchase in the new SDK.

  • transactionReceipt,purchaseToken are not available on Purchases when using Sk

  • currency is no longer available in Product of Subscription objects, use localizedPrice instead

Event Listeners

In Sk1 we have Promoted product, purchase updated and purchase error In Sk2 we have Transaction Updated. Purchase updated and purchase error and only for backward compatibility and will be removed on a future iteration.

Note that the Transaction Updated Listener accepts TransactionEvents that can be either an error or a valid transaction.

Why change the Event Listeners?

The new native libraries allow us to move away from sending events and instead returning responses for events that are generated by user interaction. Having both models becomes hard to document so we are phasing it out and keeping only one listener for events outside the normal purchase flow. For example getAvaiableItems was both posting events and returing the list of events. That won't be the case when using Sk2, it will only return the list of Transactions. If you still want to get the events published in Sk1, use the optional parameter {alsoPublishToEventListener:true} in getAvailableItems

getAvailableItems on Sk2

Another important distinction is that this method now returns the user's purchased items consistently. Meaning that the state of the transaction won't change when calling it a second time