You must be able to restore your users purchases at the click of a button. This is an iOS App Store policy.
A quick note on the blocks above. users have asked where the individualPurchaes variable comes from.
First show the hider to block user interaction, then call Get Purchase History
List of Purchase info
will output a list of objects that are formatted like this:
Assign a temporary variable as an empty list.
If there's not an error, pass the List of Purchase Info
to the Restore Previous Purchases
function, else handle the error.
Handling restoration will look different for each app, however in general it should follow this general format.
Notice the _listOfPurchases variable. you can create that by clicking the cog wheel, dragging an input name
block into the inputs
receiver, and giving it a meaningful name
Loop through the list of purchases. You can access this variable by right clicking on the function body and selecting create _listOfPurchases
Notice that the 'for each item' variable name is 'individualPurchase'. See how to change those variable names below.
in the loop, you will first check if that purchases product_id matches one of your known products, and then the purchaseState to ensure the product's purchase is still valid.
There should be one of these for each item you have in your app using an if/else if/else allowing for 1 check per product.
if the item passed the checks in step 6, check if purchasedItems
list contains that purchase and if not, add it to the list.
The final step is to save the state of the purchase locally so that you do not need to verify purchases every day. It is recommended to regularly check that subscriptions are still valid.
In this example, we store a T/F value for the purchase as well as the transactionReceipt. This allows the app to permit/block access to the purchased item and allows the app to check if the purchase is still valid again in the future.
In our example, we display an alert to the user to display the restored purchases. This is not required, though highly recommended as your users will appreciate that information. The main purpose of a workflow like this would be to be able to restore purchases if the user has to reinstall the app or changes phone