# 恢复购买

> 让玩家在重新安装应用或切换设备时能够重新访问以前拥有的商品和订阅。

Restore Purchase（恢复购买）功能允许玩家访问以前拥有的非消耗品商品以及活跃且可续订的订阅，而无需再次付费。应用商店会保留这些授权的永久记录，Unity IAP 可以检索它们以授予访问权限。

Apple 平台上不可续订的订阅无法恢复。如果在 Apple 上使用不可续订的订阅，则必须维护自己的订阅记录并在设备之间同步授权。

## Google Play##google-play

* 重新安装后，Unity IAP 会在第一次`StoreController.FetchPurchases()`调用时恢复拥有的商品。
* IAP 使用包括所有购买（所有状态）的 `Orders` 对象来调用 `OnPurchasesFetched` 监听器。
* 如果 `PurchaseService.ProcessPendingOrdersOnPurchasesFetched` 设置为 true，则 IAP 会为每个未实现的购买调用 `OnPurchasePending` 监听器。
* 同一会话中的后续`FetchPurchases()`调用不会触发开发者在同一会话中已经看到的订单的`OnPurchasePending`。

## Apple 平台##apple-platforms

* 您必须提供 Restore Purchases 按钮（Apple 强制提供）。
* 该按钮会调用请求 Apple 重新同步交易的`PurchaseService.RestoreTransactions`来重新同步交易，并可能提示用户进行身份验证。
* 重新同步后，Unity IAP 会调用 `FetchPurchases` 并调用 `OnPurchasesFetched`，其中包含用户的所有交易。

### 恢复购买（Apple 平台）##restore-purchases-(apple-platforms)

```cs
void RestorePurchases()
    {
        UnityIAPServices.StoreController().RestoreTransactions((success, error) =>
        {
            if (success) {
                // This does not mean anything was restored,
                // merely that the restoration process succeeded.
            } else {
                // Restoration failed. `error` 包含失败原因。
            }
        });
    }
```
