简体   繁体   English

SwiftUI 自动续订订阅流程

[英]SwiftUI Auto-Renewable Subscription flow

I have implemented In-App Purchase Auto-Renewable Subscription into my app but I'm not sure if I have done it correctly as the app constantly asks for iTunes login.我已经在我的应用程序中实现了应用内购买自动续订订阅,但我不确定我是否正确地完成了它,因为应用程序不断要求登录 iTunes。

In the user case: I am subscribed to monthly payments and my first month is over and expect it to auto-renew.在用户案例中:我订阅了每月付款,并且我的第一个月已经结束,并希望它能够自动续订。

The flow I have at the moment is as follows...我目前的流程如下......

  1. (in App Delegate) Check receipt is valid (在 App Delegate 中)支票收据有效

  2. (if receipt IS valid) check all receipts for latest expiration date (如果收据有效)检查所有收据的最新到期日期

  3. (if expired - which seems to be the case after the first month is over) call SKReceiptRefreshRequest to get latest receipts. (如果过期 - 第一个月结束后似乎就是这种情况)致电 SKReceiptRefreshRequest 以获取最新收据。 I have put a count check on this otherwise it gets stuck in a never ending loop.我对此进行了计数检查,否则它会陷入永无止境的循环。

  4. Do final check to see if latest receipt is in-fact expired.做最后检查以查看最新收据是否实际上已过期。

Is this the correct way to go about this?这是 go 关于这个的正确方法吗? If not could you shine some light on this?如果没有,您能否对此有所了解?

It all seems to be working fine apart from the annoyance of iTunes login.除了 iTunes 登录的烦恼之外,这一切似乎都运行良好。 Which I guess would only be once a month outside of the Sandbox environment which isn't too bad but just want to be sure I'm doing this correctly.我想在沙盒环境之外每月只有一次,这还不错,但只是想确保我做对了。

Thanks谢谢

Don't call SKReceiptRefreshRequest.不要调用 SKReceiptRefreshRequest。 This request is usually only for the "restore purchases" mechanism.这个请求通常只针对“恢复购买”机制。 This is why you're getting the sign in dialogue.这就是为什么您要在对话中登录。 StoreKit will return to you as long as you an observer to the payment queue: https://developer.apple.com/documentation/storekit/skpaymentqueue/1506042-add so you should add yourself to the payment queue on app launch.只要您是支付队列的观察者,StoreKit 就会返回给您: https://developer.apple.com/documentation/storekit/skpaymentqueue/1506042-add所以您应该在应用启动时将自己添加到支付队列中。 Then keep that object aline to listen for changes for the entire app lifecycle.然后让 object 保持一致,以监听整个应用生命周期的变化。 You will receive the renewals in the updatedTransactions callback https://developer.apple.com/documentation/storekit/skpaymenttransactionobserver/1506107-paymentqueue您将在 updatedTransactions 回调https://developer.apple.com/documentation/storekit/skpaymenttransactionobserver/1506107-paymentqueue中收到续订

Secondly, you should be doing receipt validation on your own server and not on the client as it will be susceptible to a MITM attack.其次,您应该在自己的服务器上而不是在客户端上进行收据验证,因为它容易受到 MITM 攻击。 You can also easily control the logic there and receive Server to server notifications which is best for managing subscriptions.您还可以轻松控制那里的逻辑并接收最适合管理订阅的服务器到服务器通知。

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

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