且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

我应该何时验证应用内购买交易收据?

更新时间:2022-12-31 09:47:47

场景2.
如果互联网爆炸,你将无法进入-finishTransaction。
但这很酷,因为你可以重试(NSTimer),你的应用程序将在启动时获得未完成的交易。
这就是完全 StoreKit的设计方式(尽管从阅读文档中看不出来)。

Scenario 2. If the internet blows up, you won't get to -finishTransaction. But that's cool, cause you can retry (NSTimer) and your app will be given the unfinished transaction on start up. And that's exactly how StoreKit is designed to work (even though it's not obvious from reading the docs).

StoreKit随附交易,有充分理由。用户可以在购买后立即退出应用程序,您仍然需要从中恢复。
这就是为什么Apple建议在应用程序生命周期中尽快设置您的事务观察器。

StoreKit comes with transactions, for a good reason. The user can simply quit the app right after purchasing, and you still have to recover from that. And that's why Apple recommends to set your transaction observer as soon as possible in the app lifecycle.

在提供内容之前,不要完成事务,你必须在StoreKit之上实现你自己的交易系统,你不想那样做,相信我(我已经看过它,这是一场灾难)。

Don't ever finish the transaction before providing the content, you'll have to implement your own transaction system on top of StoreKit, and you don't want to do that, believe me (I've seen it done, it was a disaster).

编辑:老实说,用户最终在购买之后和验证之前关闭了互联网,这是非常低的。这家伙在一秒钟之前上网了,没有人只是在购买过程中出去切断互联网。
但是当时用户可能会被打断并将您的应用程序发送到后台。
您的应用程序可能因iOS认为合适的原因而被杀死。
当你的应用程序再次启动时,你的应用程序将不会记得开始购买,并且商店套件不会有很大的帮助,因为你已经完成了交易。

in all honesty, the eventually of a user turning the internet off after purchase and before you validate is ridiculously low. The guy was on they internet a second ago, nobody just goes out to cut the internet in the middle of a purchase. But it's possible that the user gets interrupted at that the moment and send your app to the background. Your app can then get killed for whatever reason iOS deems appropriate. And when you're apps starts again, well your app won't remember having a purchase to start with, and store kit won't be of big help, since you've already finished the transaction.