- Home /
Restore IAP in IOS unity 5.3
As the documentation says "On Apple platforms users must enter their password to retrieve previous transactions so your application must provide users with a button letting them do so"
SO i should provide a simple button saying "Restore Purchase" and call
public void OnInitialized(IStoreController controller, IExtensionProvider extensions)
{
extensions.GetExtension<IAppleExtensions> ().RestoreTransactions (result => {
if (result) {
// This does not mean anything was restored,
// merely that the restoration process succeeded.
} else {
// Restoration failed.
}
});
}
Is that it ?
Answer by phil_me_up · Mar 02, 2016 at 11:20 AM
Pretty much.
You only need to include this if you have non-consumable items as an IAP though (setup in iTunes Connect).
You'll also probably want to take some action in your UI / save data if it's not already handled to reflect the fact that some items may now be restored.
how do i get the information that some items are there that can be restored ?
The function doesn't manages everything automatically , once user has entered the password ? i.e i have only 1 IAP to be restored out of 3 IAP.
I don't use the Unity IAP API myself as we have our own system, but looking at the docs here: http://docs.unity3d.com/$$anonymous$$anual/UnityIAPRestoringTransactions.html the important lines are:
ANDROID "On platforms that support it (e.g. Google Play and Universal Windows Applications) Unity IAP automatically restores any products the user owns during the first initialization following reinstallation; the ProcessPurchase method of your IStoreListener will be called for each owned item."
IOS "During this process the ProcessPurchase method of your IStoreListener will be invoked for any items the user already owns.""
This means that any class which implements IStoreListener will have the ProcessPurchase method called on it, which is exactly the same function you should be calling when actually buying the item in the first place (and probably where you change UI states / update save data etc).
One important thing which many people overlook is that these objects should probably be active at the time of restoration. This means that you probably want to ensure that the IStoreListener item is on some game object that is always active (like in a manager class) rather than attached to a UI element.