简体   繁体   English

针对应用内购买的自动续订订阅

[英]Auto-Renewable subscription for in-app purchase

After buying a product from in-app purchase (Auto-renewable), I hit API on server to give buying information. 从应用程序内购买(自动更新)购买产品后,我点击服务器上的API来提供购买信息。

How to know that product is re-new for hitting API ? 如何知道该产品是否适用于推出API?

When user cancel that subscription, how to known that ? 当用户取消该订阅时,如何知道?

Swift 3: In order for you to detect when the user has cancelled the subscription you need to do the following; Swift 3:为了让您检测用户何时取消订阅,您需要执行以下操作:

  1. Download the app receipt 下载应用收据
  2. Validate the receipt so you can get the json back containing all the in-app purchases and subscriptions dictionaries 验证收据,以便您可以返回包含所有应用内购买和订阅词典的json
  3. Now inside each receipt there is a field in the dictionary called cancellation_date if this is subscription purchase and otherwise not available for other in-app purchases. 现在,在每个收据中,如果这是订阅购买,则字典中有一个名为cancellation_date的字段,否则不能用于其他应用内购买。 If this is nil then there's no cancellation occurred, but if this has a value which contains the cancellation date then a cancellation did occurred and according to apple: 如果这是零,那么没有取消,但如果它有一个包含取消日期的值,那么取消确实发生了,并根据苹果:

    Cancellation Date For a transaction that was canceled by Apple customer support, the time and date of the cancellation. 取消日期对于Apple客户支持取消的交易,取消的时间和日期。

    Treat a canceled receipt the same as if no purchase had ever been made. 对已取消的收据进行处理,就像没有进行任何购买一样。

then link below explains all the fields you can use inside the receipts; 然后,下面的链接说明了您可以在收据中使用的所有字段;

https://developer.apple.com/library/ios/releasenotes/General/ValidateAppStoreReceipt/Chapters/ReceiptFields.html https://developer.apple.com/library/ios/releasenotes/General/ValidateAppStoreReceipt/Chapters/ReceiptFields.html

Code Example: 代码示例:

// Create receipt request
 let receiptRefreshRequest = SKReceiptRefreshRequest()

// Get the receiptUrl from the main bundle
 let receiptUrl = Bundle.main().appStoreReceiptURL

 //If the receipt file exist on local device
 if (receiptUrl as NSURL?)?.checkResourceIsReachableAndReturnError(nil) == true{

            // Get the file as data
            let receipt: Data = try! Data(contentsOf: receiptUrl!)


  }

now you send the receipt to apple server to validate it using your server as apple recommend. 现在您将收据发送到苹果服务器,以使用您的服务器验证它作为苹果推荐。 After you get callback from the validation you check the cancellation date. 从验证中获得回调后,您将检查取消日期。

Apple does not provide anything built into iOS or a REST API that gives you simple subscription details, nor are there any callbacks that you can listen for and respond to in regards to renewal or cancellation. Apple不提供内置于iOS或REST API中的任何内容,可为您提供简单的订阅详细信息,也不存在任何可以在续订或取消方面收听和回复的回调。 Apple does have an API that, when given a user's local receipt and a “shared secret” generated in iTunes Connect, returns a JSON object of the user's purchase history for your app, including their current subscription information. Apple确实有一个API,当给定用户的本地收据和iTunes Connect中生成的“共享密钥”时,会返回用户的应用程序购买历史记录的JSON对象,包括其当前的订阅信息。 More Information check this link 更多信息请查看此链接

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM