2.4.1
0.59.3
IOS
Restore available auto-renewable subscriptions
Restore auto-renewable subscriptions in different devices.
iPhone 6s Plus
call and priny the results of await RNIap.getAvailablePurchases() and await RNIap.getPurchaseHistory() methods orderly
After purchasing auto-renewable subscriptions I want to restore purchased subscriptions in different devices. As mentioned in Deprecated Readme (iOS Purchasing process right way)
Non-consumable products can be restored via getPurchaseHistory function
but in documentation getAvailablePurchases() is used to restore purchases. In my tests, the result of RNIap.getAvailablePurchases() and RNIap.getPurchaseHistory() has different items and sizes.
I am very confused which one is the restored items. Which method should be used? Which one is the latest valid restored subscription?
Thank you.

Have you went through this?
Yes, when I call getAvailablePurchases() 9 elements returns but when I call getPurchaseHistory() 2 elements returns. But the bottom images shows that restoring should be done with getAvailablePurchases(). As you can see non-consumable products mentioned in either with getAvailablePurchases() and getPurchaseHistory(). Which one is correct?



Also I can not understand how these methods returns different items while calling the same action?
/**
* Gets an invetory of purchases made by the user regardless of consumption status
* @returns {Promise<Purchase[]>}
*/
export const getPurchaseHistory = () => Platform.select({
ios: async() => {
checkNativeiOSAvailable();
return RNIapIos.getAvailableItems();
},
//...
})();
/**
* Get all purchases made by the user (either non-consumable, or haven't been consumed yet)
* @returns {Promise<Purchase[]>}
*/
export const getAvailablePurchases = () => Platform.select({
ios: async() => {
checkNativeiOSAvailable();
return RNIapIos.getAvailableItems();
},
//...
})();
as you can see two methods returns RNIapIos.getAvailableItems();
RCT_EXPORT_METHOD(getAvailableItems:(RCTPromiseResolveBlock)resolve
reject:(RCTPromiseRejectBlock)reject) {
[self addPromiseForKey:@"availableItems" resolve:resolve reject:reject];
[[SKPaymentQueue defaultQueue] restoreCompletedTransactions];
}
As I know restoreCompletedTransactions restores the purchases. So these two methods restoring the purchases. Where am I wrong?
Did you follow #275?
Yes. I did my restoring process as @andrewzey solution.
const availablePurchases = await RNIap.getAvailablePurchases();
const sortedAvailablePurchases = availablePurchases.sort(
(a, b) => b.transactionDate - a.transactionDate
);
const latestAvailableReceipt = sortedAvailablePurchases[0].transactionReceipt;
Now it is working correctly in my tests.
Thank you
Thanks for coming back. I'll close this for now.
Most helpful comment
Yes. I did my restoring process as @andrewzey solution.
Now it is working correctly in my tests.
Thank you