In-App Purchase Programming Guide----(七) ----Restoring Purchased Products

Restoring Purchased Products


Users restore transactions to maintain access to content they’ve already
purchased. For example, when they upgrade to a new phone, they don’t lose all of
the items they purchased on the old phone. Include some mechanism in your app to
let the user restore their purchases, such as a Restore Purchases button.
Restoring purchases prompts for the user’s App Store credentials, which
interrupts the flow of your app: because of this, don’t automatically restore
purchases, especially not every time your app is launched.

In most cases, all your app needs to do is refresh its receipt and deliver
the products in its receipt. The refreshed receipt contains a record of the
user’s purchases in this app, on this device or any other device. However, some
apps need to take an alternate approach for one of the following reasons:

  • If you use Apple-hosted content, restoring completed transactions gives
    your app the transaction objects it uses to download the content.

  • If you need to support versions of iOS earlier than iOS 7, where the app
    receipt isn’t available, restore completed transactions instead.

  • If your app uses non-renewing subscriptions, your app is responsible for
    the restoration process.

Refreshing the receipt asks the App Store for the latest copy of the receipt.
Refreshing a receipt does not create any new transactions. Although you should
avoid refreshing multiple times in a row, this action would have same result as
refreshing it just once.

Restoring completed transactions creates a new transaction for every
completed transaction the user made, essentially replaying history for your
transaction queue observer. While transactions are being restored, your app
maintains its own state to keep track of why it’s restoring completed
transactions and how it needs to handle them. Restoring multiple times creates
multiple restored transactions for each completed transaction.

Note: If the user attempts to purchase a product that’as
already been purchased, rather than using your app’s restoration interface, the
App Store creates a regular transaction instead of a restore transaction. The
user isn’t charged again for the product. Treat these transactions the exact
same way you treated the original transactions.

Give the user an appropriate level of control over what content is
redownloaded. For example, don’t download three years worth of daily newpapers
or hundreds of megabytes worth of game levels all at once.

Refreshing the App Receipt

Create a receipt refresh request, set a delegate, and start the request. The
request supports optional properties for obtaining receipts in various states
during testing such as expired receipts—for details, see the values for
the initWithReceiptProperties: method
of SKReceiptRefreshRequest.








request = [[SKReceiptRefreshRequest alloc] init];
request.delegate = self;
[request start];

After the receipt is refreshed, examine it and deliver any products that were
added.

Restoring Completed Transactions

Your app starts the process by calling the restoreCompletedTransactions method
of SKPaymentQueue. This sends a request to the App Store
to restore all of your app’s completed transactions. If your app sets a value
for the applicationUsername property of its payment
requests, as described in “Detecting
Irregular Activity,”
 use the restoreCompletedTransactionsWithApplicationUsername: method
to provide the same information when restoring transactions.

The App Store generates a new transaction for each transaction that was
previously completed. The restored transaction has a reference to the original
transaction: instances of SKPaymentTransaction have a originalTransaction property, and the entries in
the receipt have an Original Transaction Identifier field.

Note: The date fields have slightly different meanings for
restored purchases. For details, see the Purchase Date and Original Purchase
Date fields in Receipt Validation Programming Guide.

Your transaction queue observer is called with a status of SKPaymentTransactionStateRestored for each
restored transaction, as described in “Waiting
for the App Store to Process Transactions.”
 The action you take
at this point depends on the design of your app.

  • If your app uses the app receipt and doesn’t have Apple-hosted content,
    this code isn’t needed because your app doesn’t restore completed
    transactions. Finish any restored transactions immediately.

  • If your app uses the app receipt and has Apple-hosted content, let the user
    select which products to restore before starting the restoration process.
    During restoration, re-download the user-selected content and finish any other
    transactions immediately.




















    NSMutableArray *productIDsToRestore = <# From the user #>;

    SKPaymentTransaction *transaction = <# Current transaction #>;

     
    if ([productIDsToRestore containsObject:transaction.transactionIdentifier]) {

        // Re-download the Apple-hosted content, then finish the transaction

        // and remove the product identifier from the array of product IDs.

    } else {
        [[SKPaymentQueue defaultQueue] finishTransaction:transaction];

    }

  • If your app doesn’t use the app receipt, it examines all completed
    transactions as they’re restored. It uses a similar code path to the original
    purchase logic to make the product available and then finishes the
    transaction.

    Apps with more than a few products, especially products with associated
    content, let the user select which products to restore instead of restoring
    everything all at once. These apps keep track of which completed transactions
    need to be processed as they’re restored and which transactions can be ignored
    by finishing them immediately.

NextPrevious

In-App Purchase Programming Guide----(七) ----Restoring Purchased
Products

时间: 2025-01-08 12:20:35

In-App Purchase Programming Guide----(七) ----Restoring Purchased Products的相关文章

In-App Purchase Configuration Guide for iTunes Connect---(一)----Introduction

Introduction In-App Purchase is an Apple technology that allows your users to purchase content and services from within your app. You set up In-App Purchase products through iTunes Connect, a suite of web-based tools. You implement In-App Purchase in

In-App Purchase Programming Guide----(八) ---- Preparing for App Review

Preparing for App Review After you finish testing, you’re ready to submit your app for review. This chapter highlights a few tips to help you through the review process. 当你完成测试以后,就表示已经准备好提交应用以供审核. 该章节重点介绍了一些提示来帮助你通过审核过程. Submitting Products for Revie

In-App Purchase Programming Guide----(六) ----Working with Subscriptions

Working with Subscriptions Apps that use subscriptions have some additional behaviors and considerations. Because subscriptions incorporate an element of time, your app needs to have the appropriate logic to determine whether the subscription is curr

Core Bluetooth Programming Guide - Performing Common Peripheral Role Tasks 粗译

Core Bluetooth Programming Guide 粗译 续 code {padding:0.2em 0.4em; background:#e1e9ed;} pre {text-align:left; overflow-x: scroll; color: #d3bd7e; background: #202020; padding: 10pt 15pt; border-radius: 3px;} hr {border: 0px; border-top: 1px solid #ddd;

笔记:View Programming Guide for iOS -1

原文:View Programming Guide for iOS View and Window Architecture Views and windows present your application’s user interface and handle the interactions with that interface. UIKit and other system frameworks provide a number of views that you can use a

apple官方文档翻译:URL Loading System Programming Guide

URL Loading System Programming Guide (本文为概要描述,部分有删减) 原文链接 关于 本指南描述了使用标准Internet协议来处理Urls.与服务器通信的相关类. URL Loading System包含了一系列类和协议,来支持app访问URL上的内容.核心类是NSURL,帮助app来控制URL以及该URL指向的内容. 为了支持NSURL,apple的Foundation framework提供了丰富的类来帮助你加载URL的内容,从服务器更新数据,管理coo

AppStore苹果应用支付开发(In App Purchase)翻译

http://yarin.blog.51cto.com/1130898/549141 一.In App Purchase概览 Store Kit代表App和App Store之间进行通信.程序将从App Store接收那些你想要提供的产品的信息,并将它们显示出来供用户购买.当用户需要购买某件产品时,程序调用StoreKit来收集购买信息.下图即为基本的store kit 模型: Store Kit的API只是为程序添加In App Purchase功能的一小部分.你需要决定如何去记录那些你想要提

Quartz 2D Programming Guide

Quartz 2D Programming  Guide 官方文档: Quartz 2D Programming Guide 译文: Quartz 2D编程指南(1) - 概览 Quartz 2D编程指南(2) - 图形上下文(Graphics Contexts) Quartz 2D编程指南(3) - 路径(Paths)[上] Quartz 2D编程指南(3) - 路径(Paths)[下] Quartz 2D编程指南(4) - 颜色和颜色空间 Quartz 2D编程指南(5) - 变换 Quar

View Programming Guide for iOS 视图编程指南 - iOS

1 有关 Windows and Views 每个应用都至少有一个 window 和一个 view. 1.1 添加额外的 Window 一般在有外界显示设备的时候才需要添加额外的 window 下面的代码举了一个例子,这里假定对象实现了方法 externalWindow,externalWindow 存储一个 window 的引用 - (void)configureExternalDisplayAndShowWithContent:(UIViewController*)rootVC { // C