iOS 在应用购买中。如何查看购买是否已经购买?

iOS in app purchase. How to check if purchase already bought?

我正在尝试将购买添加到我的应用程序中。但我不知道如何检查购买是否已经购买。据我了解,当有人购买时,我需要将其存储到 UserDefaults 或 KeyChain 中,然后检查它是否已经存在(这意味着该购买已经购买)。但是当用户购买了另一台设备时呢?

我有代码可以提供有关 iTunes 中所有购买的信息。

func productsRequest(request: SKProductsRequest!, didReceiveResponse response: SKProductsResponse!) {

    }

响应对象有两个变量:"products"和"invalidProductIdentifiers"。但据我了解,产品包含来自 iTunes 的所有产品,而 invalidProductIdentifiers 包含我要求检查但 Apple 无法识别的所有标识符。所以我可以在哪里检查购买是否已经购买。

假设 iOS 7+,您应该验证收据,ala A complete solution to LOCALLY validate an in-app receipts and bundle receipts on iOS 7 以确定购买了什么,什么是有效的(在订阅或消耗品的情况下),以及其他评论,提供一个 "Restore Purchases" UI 元素,允许用户将可共享的购买干净地传播到新的 restored/acquired 设备。

AFA 响应对象,即目录(可购买物品)信息,而不是关于已购买物品的信息。为了让 IAP 正常工作,资产将由 Apple 批准,类似于应用程序本身,并在 iTunes Connect 中由您自己控制 "ready for sale"。对于该通行证,您向 Apple 发送您想要提供的时间的完整列表,Apple returns 向您发送列表,该列表分为 "if your user tries to buy this, they will succeed"(产品)和 "if your user tries to buy this, they will fail"(invalidProductIdentifiers) .

当您与 sandbox/iTunes Connect Test 用户一起测试时,您的产品不需要 Apple 批准,但对于生产代码他们需要。