鍍金池/ 教程/ iOS/ 使用訂閱
恢復(fù)購買記錄
內(nèi)置購買
介紹
準(zhǔn)備應(yīng)用程序?qū)彶?/span>
創(chuàng)建和配置產(chǎn)品
獲取產(chǎn)品信息
支付請求
使用訂閱
如何測試應(yīng)用程序內(nèi)置購買
產(chǎn)品交付

使用訂閱

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 currently active and what time periods the subscription was active in the past. Your app also needs to react to new and renewed subscriptions, and properly handle expired subscriptions. Figure 5-1 shows an example subscription timeline, including some of the complexities your app needs to handle.

使用訂閱 (subscriptions) 的應(yīng)用有一些額外的行為和注意事項 (considerations) 。 因為訂閱包含時間元素,應(yīng)用程序需要有適當(dāng)?shù)倪壿媮頉Q定訂閱當(dāng)前是否處于活動狀態(tài)以及過去該訂閱活動的時間段。 應(yīng)用程序還需要應(yīng)對新的和更新的訂閱,并且需要正確地處理過期訂閱。 圖5-1 舉了一個訂閱時間表的例子,包括一些應(yīng)用程序需要處理的復(fù)雜事項 (complexities )。

Figure 5-1 Example subscription timeline

http://wiki.jikexueyuan.com/project/in-app-purchase/images/9.png" alt="" />

Calculating a Subscription’s Active Period

一、計算一個訂閱的活動期 Your app needs to determine what content the user has access to based on the period of time the subscription was active. Consider, for example, a user with a subscription to a magazine that publishes a new issue on the first day of each month, following the timeline shown in Table 5-1.

應(yīng)用程序需要在訂閱處于活動狀態(tài)的期間內(nèi)決定用戶訪問什么內(nèi)容。 舉個例子,一個用戶訂閱了一個雜志,該雜志在每個月的第一天發(fā)布新刊,如圖5-1中的時間表:

Table 5-1 Timeline of a sample subscription 表 5-1 一個示例訂閱的時間表

http://wiki.jikexueyuan.com/project/in-app-purchase/images/10.png" alt="" />

To implement this logic in your app, keep a record of the date that each piece of content is published. Read the Original Purchase Date and Subscription Expiration Date field from each receipt entry to determine the start and end dates of the subscription. (For information about the receipt, see Receipt Validation Programming Guide.) The user has access to all content published between each start and end date, as well as the content that was initially unlocked when the subscription was purchased. If the subscription lapsed, there will be multiple periods of time during which the subscription was active, and there will be pieces of content unlocked at the beginning of a subscription period.

要想在應(yīng)用程序中實現(xiàn)該邏輯,保留一個關(guān)于每刊內(nèi)容發(fā)布的日期記錄。 從每個收據(jù)項目中讀取初始購買日期和訂閱到期時期來決定訂閱的開始和結(jié)束日期。 (關(guān)于收據(jù)的更多信息,請看 Receipt Validation Programming Guide.) 用戶可以訪問所有在開始日期和結(jié)束日期之間發(fā)布的內(nèi)容以及它初次購買時解鎖的內(nèi)容。 如果訂閱失效(lapsed),將由訂閱活動期間的多個時間期,以及在一個訂閱期的開始時又多刊內(nèi)容解鎖。

Note: Don’t calculate the subscription period by adding a subscription duration to the purchase date. This approach fails to take into account the free trial period, the marketing opt-in period, and the content made available immediately after the user purchased the subscription.

注意:不要通過添加一個訂閱持續(xù)時間到購買日期中來計算訂閱期。 該方法沒有考慮到應(yīng)用試用期,市場選擇期,并讓用戶購買了訂閱之后馬上解鎖內(nèi)容。

Continuing the example from Table 5-1, the receipt would show the following start and end dates:

從表5-1開始繼續(xù)示例,收據(jù)將顯示以下開始和結(jié)束日期:

  • February 20 – March 20

  • March 20 – April 20

  • (The lapse from April 20 – June 17 is not recorded explicitly in the receipt.)

  • June 17 – July 17

The user has access to the February and June issues because they were initially unlocked when the subscription was purchased or restarted.

用戶可以訪問二月和六月刊,因為它們時在訂閱被購買或重新訂閱時解鎖的內(nèi)容。

The user has access to the March, April, June, and July issues because the subscription is active at those times.

用戶可以訪問三月,四月,六月以及七月刊,因為在這些時間訂閱是活動的。

Expiration and Renewal

二、到期和續(xù)訂

The renewal process begins with a “preflight” check, starting ten days before the expiration date. During those ten days, the App Store checks for any issues that might delay or prevent the subscription from being automatically renewed—for example, if the customer no longer has an active payment method, if the product’s price increased since the user bought the subscription, or if the product is no longer available. The App Store notifies users of any issue so that they can resolve it before the subscription needs to renew, ensuring their subscription isn’t interrupted.

續(xù)訂過程在到期日期前10天開始預(yù)檢。 在那10天中,應(yīng)用商店檢查任何可能導(dǎo)致自動續(xù)訂延遲或無法續(xù)訂的情況---比如,如果用戶沒有一個可用的支付方法,如果用戶購買了訂閱之后,產(chǎn)品價格升了,又或者如果產(chǎn)品已經(jīng)不存在。 應(yīng)用商店通知用戶任何問題,這樣他們就可以在續(xù)訂之前解決這些問題,以確保不會終止他們的續(xù)訂。

Note: Increasing the price of a subscription doesn’t disable automatic renewal for all customers, only for those customers whose subscription expires in the next ten days. If this change is a mistake, changing it back to the original price means no additional users are affected. If this change is intentional, keeping the new higher price causes automatic renewal to be disabled for the rest of your users in turn as they enter the ten-day renewal window.

注意:提高訂閱價格并不會終止所有用戶的自動續(xù)訂,只要那些用戶的到期時間是在未來10天之內(nèi)。 如果該價格改變是一個錯誤,把價格改回原來的價格并不會影響任何用戶。 如果是有意的提交價格,一直保留該新價格將導(dǎo)致依次進(jìn)入10天續(xù)訂窗口的其他用戶不能進(jìn)行自動續(xù)訂。

During the 24-hour period before the subscription expires, the App Store starts trying to automatically renew it. The App Store makes several attempts to automatically renew the subscription over a period of time but eventually stops if there are too many failed attempts.

在訂閱到期的前24個小時期間,應(yīng)用商店開始嘗試自動續(xù)訂。 盡管應(yīng)用商店在自動續(xù)訂期間會多次嘗試自動續(xù)訂,但是如果失敗次數(shù)太多則會終止自動續(xù)訂。

The App Store renews the subscription slightly before it expires, to prevent any lapse in the subscription. However, lapses are still possible. For example, if the user’s payment information is no longer valid, the first renewal attempt would fail. If the user doesn’t update this information until after the subscription expires, there would be a short lapse in the subscription between the expiration date and the date that a subsequent automatic renewal succeeds. The user can also disable automatic renewal and intentionally let the subscription expire, then renew it at a later date, creating a longer lapse in the subscription. Make sure your app’s subscription logic can handle lapses of various durations correctly.

盡管應(yīng)用商店在它快要過期之前自動續(xù)訂來防止丟失任何訂閱。 但是,任然有可能丟失。比如,如果用戶的支付信息已經(jīng)失效,第一次續(xù)訂將失敗。 如果用戶一直不更新該支付信息直到訂閱到期,在到期時間和下一次自動續(xù)訂成功之前這段時間將有一小段時間的丟失。 用戶也可以關(guān)閉自動續(xù)訂并故意讓訂閱到期,然后在以后續(xù)訂它,長期丟失訂閱。 請確定你的應(yīng)用程序的訂閱邏輯能正確地處理不同時間的丟失。

After a subscription is successfully renewed, Store Kit adds a transaction for the renewal to the transaction queue. Your app checks the transaction queue on launch and handles the renewal the same way as any other transaction. Note that if your app is already running when the subscription renews, the transaction observer is not called; your app finds out about the renewal the next time it’s launched.

當(dāng)成功續(xù)訂之后,商店Kit把續(xù)訂交易添加到交易隊列中。應(yīng)用程序在啟動時檢查交易隊列并且同處理其它任何交易一樣處理它。 注意如果在續(xù)訂時應(yīng)用程序已經(jīng)運行,那么交易觀察者將不被調(diào)用;應(yīng)用程序在下一次啟動時找到續(xù)訂記錄。

Cancellation

三、取消

A subscription is paid for in full when it’s purchased and can be refunded only by contacting Apple customer service. For example, if the user accidentally buys the wrong product, customer support can cancel the subscription and issue a refund. It’s not possible for customers to change their mind in the middle of a subscription period and decide they don’t want to pay for the rest of the subscription.

購買了一個訂閱后得全額付款,只有通過聯(lián)系蘋果客服服務(wù)才能退款。 比如,如果用戶意外買錯了產(chǎn)品,客服中心可以取消該交易并退款。 用戶不能在一個訂閱周期中間改變注意不支付剩余的訂閱。

To check whether a purchase has been canceled, look for the Cancellation Date field in the receipt. If the field has a date in it, regardless of the subscription’s expiration date, the purchase has been canceled—treat a canceled receipt the same as if no purchase had ever been made.

要想確認(rèn)某次交易是否已經(jīng)被取消,在收據(jù) (receipt) 中查找 Cancellation Date (取消日期)字段。 如果該字段有日期,不管該訂閱的過期日期是什么,該交易都已經(jīng)被取消---取消交易就是跟一直沒有購買過一樣。

Depending on the type of product, you may be able to check only the currently active subscription, or you may need to check all past subscriptions. For example, a magazine app would need to check all past subscriptions to determine which issues the user had access to.

根據(jù)產(chǎn)品類型,你或許只能檢查當(dāng)前的活動交易,或者你可能需要檢查過去所有的交易。比如,一個雜志應(yīng)用需要檢查過去所有的交易來決定用戶訪問了那些期刊。

Cross-Platform Considerations

四、跨平臺注意事項

Product identifiers are associated with a single app. Apps that have both an iOS and OS X version have separate products with separate product identifiers on each platform. You could let users who have a subscription in an iOS app access the content from an OS X app (or vice versa), but implementing that functionality is your responsibility. You would need some system for identifying users and keeping track of what content they’ve subscribed to, similar to what you would implement for an app that uses non-renewable subscriptions.

產(chǎn)品識別碼只能綁定到一個應(yīng)用程序。同時有 iOS 和 OS X 版本的應(yīng)用程序是不同的應(yīng)用程序并分別帶有不同的產(chǎn)品識別碼。 你可以讓在一個 iOS 應(yīng)用中購買了訂閱的用戶從 OS X 應(yīng)用(或其它平臺)訪問它購買的內(nèi)容,但是這功能你應(yīng)該自己實現(xiàn)。你會需要一些系統(tǒng)來識別用戶并保持跟蹤他們已經(jīng)訂閱了什么內(nèi)容,類似于你會給一個 no-renewable subscriptions (不可再生訂閱)應(yīng)用程序?qū)崿F(xiàn)什么。

Letting Users Manage Subscriptions

五、讓用戶管理訂閱

Rather than needing to code your own subscription management UI, your app can open the following URL:

不需要你自己編碼實現(xiàn)自己的訂閱管理 UI ,你的應(yīng)用程序可以打開以下 URL :

https://buy.itunes.apple.com/WebObjects/MZFinance.woa/wa/manageSubscriptions

Opening this URL launches iTunes or iTunes Store, and then displays the Manage Subscription page.

打開該 URL 啟動 iTunes 或者 iTunes 商店,然后顯示管理訂閱頁面。

The Test Environment

6、測試環(huán)境

For the sake of testing, there are some differences in behavior between auto-renewable subscriptions in the production environment and in the test environment.

為了測試,自動再生訂閱在產(chǎn)品環(huán)境 (production environment) 和 在測試環(huán)境 (test environment) 中的行為有所不同。

Renewal happens at an accelerated rate, and auto-renewable subscriptions renew a maximum of six times per day. This lets you test how your app handles a subscription renewal, a subscription lapse, and a subscription history that includes gaps.

更新發(fā)生在加速時,并且自動更新訂閱每天最多更新6次。 這樣讓里測試你的應(yīng)用程序如何處理一個訂閱更新,一個訂閱失效,以及一個包括缺口的訂閱歷史。

Because of the accelerated expiration and renewal rate, the subscription can expire before the system starts trying to renew the subscription, leaving a small lapse in the subscription period. Such lapses are also possible in production for a variety of reasons—make sure your app handles them correctly.

因為加速的到期和更新速度,訂閱可以在系統(tǒng)開始嘗試更新訂閱之前過期,在訂閱期間留下一個小失誤。 因為各種原因,這樣的失誤在產(chǎn)品中也同樣可能存在---請確保你的應(yīng)用程序可以正確地處理它們。