iOS In-App Purchase 内购之 什么是恢复购买记录

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 therestoreCompletedTransactionsmethod ofSKPaymentQueue. 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 inDetecting Irregular Activity“,” use theestoreCompletedTransactionsWithApplicationUsernamer: 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 ofSKPaymentTransactionhave aoriginalTransactionproperty, 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 inReceipt Validation Programming Guide.

注意:恢复的购买记录中的日期字段跟初始交易记录中的有稍微不同的意义。具体详情,请看Receipt Validation Programming Guide中的购买日期和初始购买日期字段。

Your transaction queue observer is called with a status ofSKPaymentTransactionStateRestoredfor each restored transaction, as described inWaiting 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.

带有多个产品的应用程序,特别是跟内容相关的产品,让用户选择恢复哪些产品,而不是一次性恢复所有交易。  这些应用保持监控哪些已完成交易需要被处理为已经恢复,哪些交易可以忽视并立即结束交易。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 206,839评论 6 482
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 88,543评论 2 382
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 153,116评论 0 344
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 55,371评论 1 279
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 64,384评论 5 374
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 49,111评论 1 285
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 38,416评论 3 400
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 37,053评论 0 259
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 43,558评论 1 300
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 36,007评论 2 325
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 38,117评论 1 334
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,756评论 4 324
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 39,324评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 30,315评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,539评论 1 262
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 45,578评论 2 355
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,877评论 2 345

推荐阅读更多精彩内容