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.
如果你需要支持iOS7以前的版本,需要存储已完成的所有交易,因为以前的版本不支持应用收据功能。
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.
适当控制用户可以重新下载的内容。 比如,不能一次下载三年量的日报,或者不能一次性下载10M大小的游戏关卡。
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.
创建一个收据刷新请求,设置一个委托,并开启该请求。 请求在测试中支持很多可选特性来获取各种状态的收据,比如到期的收据---详情请参见 SKReceiptRefreshRequest 类的initWithReceiptProperties: 方法的值:
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.
应用程序通过调用 SKPaymentQueue类的 restoreCompletedTransactions 方法来开始该过程。 这样做就是给应用商店发送一个请求让它来恢复或有应用程序中的已完成交易。 如果应用程序给它的支付请求(payment requests)的applicationUsername特性设置了一个值,正如In-App Purchase Programming Guide----(四) ----Requesting Payment 中的 “Detecting Irregular Activity,” 中所描述,在恢复交易时使用restoreCompletedTransactionsWithApplicationUsername: 方法来提供相同的信息。
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.
应用商店为每个已经购买完成的交易生产一个新的交易。 恢复的交易有一个指向最初交易的引用:SKPaymentTransaction 的实例有一个 originalTransaction 特性, 并且收据的项目(entries)中有一个初始交易识别码字段。
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.
注意:恢复的购买记录中的日期字段跟初始交易记录中的有稍微不同的意义。具体详情,请看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.
应用程序调用交易队列观察者,它带有每个恢复交易的SKPaymentTransactionStateRestored 状态。详情请看:“Waiting for the App Store to Process Transactions.” 这时你所需要做的操作取决于应用程序的设计。
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.
带有多个产品的应用程序,特别是跟内容相关的产品,让用户选择恢复哪些产品,而不是一次性恢复所有交易。 这些应用保持监控哪些已完成交易需要被处理为已经恢复,哪些交易可以忽视并立即结束交易。
In-App Purchase Programming Guide----(七) ----Restoring Purchased Products的更多相关文章
- In-App Purchase Programming Guide----(一) ---- About In-App Purchase
About In-App Purchase In-App Purchase allows you to embed a store inside your app using the Store Ki ...
- In-App Purchase Programming Guide----(五) ----Delivering Products
Delivering Products In the final part of the purchase process, your app waits for the App Store to p ...
- 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 s ...
- 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 ...
- In-App Purchase Programming Guide----(二) ---- Designing Your App’s Products
Designing Your App’s Products A product is something you want to sell in your app’s store. You creat ...
- In-App Purchase Programming Guide----(六) ----Working with Subscriptions
Working with Subscriptions Apps that use subscriptions have some additional behaviors and considerat ...
- Collection View Programming Guide for iOS---(七)---Custom Layouts: A Worked Example
Custom Layouts: A Worked Example Creating a custom collection view layout is simple with straightfor ...
- In-App Purchase Programming Guide----(三) ----Retrieving Product Information
Retrieving Product Information In the first part of the purchase process, your app retrieves informa ...
- View Controller Programming Guide for iOS---(一)---About View Controllers
About View Controllers View controllers are a vital link between an app’s data and its visual appear ...
随机推荐
- install Python 2.7 and Python 3.3 on CentOS 6
来自:http://toomuchdata.com/2014/02/16/how-to-install-python-on-centos/ In this guide I will show you ...
- SpringMVC拦截器详解[附带源码分析](转)
本文转自http://www.cnblogs.com/fangjian0423/p/springMVC-interceptor.html 感谢作者 目录 前言 重要接口及类介绍 源码分析 拦截器的配置 ...
- PR物料KFF弹出LOV - WHERE条件重写
PROCEDURE event (event_name VARCHAR2)IS---- This procedure allows you to execute your code at specif ...
- Solidworks如何将参考平面的图形投影到某曲面上
1 画好草图,点击曲线-分割线 2 选择要投影的草图和被投影的面(那个球面),最后效果如下图所示 3 为了获取连续的轨迹,我们可以再次选择这个草图,然后在投影面中选择平面,最后得到的图形如下图 ...
- 【整理】nand相关
记录nand相关知识.主要是mtd和ubi 什么是UBI 它是一种flash管理方式 flash是一系列连续的物理擦除块组成的. UBI卷是一系列连续的逻辑擦除块(eraseblock),每一块都能够 ...
- libxml/HTMLparser.h file not found
在导入asihttprequest包时出问题导入了libxml2.dylib.可是却提示libxml/HTMLparser.h file not found. 这是由于你的开发环境默认的路径无法找到这 ...
- VS2012,VS2010无法生成dll程序集的解决办法
在我们做项目的时候总会遇到dll程序集无法生成导致各种问题. 通常我们的做法就是清理项目,然后重新生成,或者直接到bin目录下删除所有dll,然后重新生成. 有时候某几个dll就是不生成. 这时候就需 ...
- 【日常学习】【二叉树遍历】Uva548 - Tree题解
这道题目本身不难,给出后序遍历和中序遍历,求到节点最小路径的叶子,同样长度就输出权值小的叶子. Uva上不去了,没法測.基本上是依照ruka的代码来的.直接上代码 //Uva548 Tree #inc ...
- Qt linux文件同步写入
因为linux 系统机制问题,文件的创建和写入并不会直接写入硬盘.而是先写入缓存,当系统要关闭或须要时才写入硬盘.为防止突然掉电,应将缓存中的文件及时同步到硬盘上去. linux 下的sync 命令具 ...
- Python中文问题研究
我曾经在深入浅出java中文问题系 列中研究过java的中文问题,现在中文问题已经不再羁绊我在java世界中漫游的脚步了.最近,对Python产生了浓厚的兴趣,谁知道跟中文问题这个 老朋友又一次不期而 ...